Skip to content

Commit d207b28

Browse files
committed
feat(flags): Pass project API key query string
Updates `remote_config` to pass the project api key in the token query string parameter. This is the same approach used by local_evaluation to ensure routing to the correct project.
1 parent 09dad81 commit d207b28

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

posthog/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,7 @@ def get_remote_config_payload(self, key: str):
16271627
try:
16281628
return remote_config(
16291629
self.personal_api_key,
1630+
self.api_key,
16301631
self.host,
16311632
key,
16321633
timeout=self.feature_flags_request_timeout_seconds,

posthog/request.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,16 @@ def flags(
132132

133133

134134
def remote_config(
135-
personal_api_key: str, host: Optional[str] = None, key: str = "", timeout: int = 15
135+
personal_api_key: str,
136+
project_api_key: str,
137+
host: Optional[str] = None,
138+
key: str = "",
139+
timeout: int = 15,
136140
) -> Any:
137141
"""Get remote config flag value from remote_config API endpoint"""
138142
return get(
139143
personal_api_key,
140-
f"/api/projects/@current/feature_flags/{key}/remote_config/",
144+
f"/api/projects/@current/feature_flags/{key}/remote_config?token={project_api_key}",
141145
host,
142146
timeout,
143147
)

posthog/test/test_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import unittest
33
from datetime import datetime
44
from uuid import uuid4
5-
from posthog.contexts import get_context_session_id, set_context_session, new_context
65

76
import mock
87
import six
98
from parameterized import parameterized
109

1110
from posthog.client import Client
11+
from posthog.contexts import (get_context_session_id, new_context,
12+
set_context_session)
1213
from posthog.request import APIError
1314
from posthog.test.test_utils import FAKE_TEST_API_KEY
1415
from posthog.types import FeatureFlag, LegacyFlagMetadata
@@ -1923,9 +1924,9 @@ def test_mock_system_context(
19231924

19241925
# Set up platform-specific mocks
19251926
if platform_method:
1926-
getattr(
1927-
mock_platform, platform_method
1928-
).return_value = platform_return
1927+
getattr(mock_platform, platform_method).return_value = (
1928+
platform_return
1929+
)
19291930

19301931
# Special handling for Linux which uses distro module
19311932
if sys_platform == "linux":
@@ -2057,7 +2058,7 @@ def test_set_context_session_with_page_explicit_properties(self):
20572058

20582059
def test_set_context_session_override_in_capture(self):
20592060
"""Test that explicit session ID overrides context session ID in capture"""
2060-
from posthog.contexts import set_context_session, new_context
2061+
from posthog.contexts import new_context, set_context_session
20612062

20622063
with mock.patch("posthog.client.batch_post") as mock_post:
20632064
client = Client(FAKE_TEST_API_KEY, on_error=self.set_fail, sync_mode=True)
@@ -2158,6 +2159,7 @@ def test_get_remote_config_payload_works_without_poller(self, patch_remote_confi
21582159
self.assertEqual(result, {"test": "payload"})
21592160
patch_remote_config.assert_called_once_with(
21602161
"test-personal-key",
2162+
FAKE_TEST_API_KEY,
21612163
client.host,
21622164
"test-flag",
21632165
timeout=client.feature_flags_request_timeout_seconds,
@@ -2282,9 +2284,7 @@ def test_get_feature_flag_result_with_empty_string_payload(self, patch_batch_pos
22822284
}
22832285
]
22842286
},
2285-
"payloads": {
2286-
"empty-variant": "" # Empty string payload
2287-
},
2287+
"payloads": {"empty-variant": ""}, # Empty string payload
22882288
},
22892289
}
22902290
]

0 commit comments

Comments
 (0)