diff --git a/CHANGELOG.md b/CHANGELOG.md index 0681e9e24..8f2eef7c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 6.4.1 - 2025-08-06 + +- fix: Always pass project API key in `remote_config` requests for deterministic project routing + # 6.4.0 - 2025-08-05 - feat: support Vertex AI for Gemini diff --git a/posthog/client.py b/posthog/client.py index 143d4630b..323e81bee 100644 --- a/posthog/client.py +++ b/posthog/client.py @@ -1644,6 +1644,7 @@ def get_remote_config_payload(self, key: str): try: return remote_config( self.personal_api_key, + self.api_key, self.host, key, timeout=self.feature_flags_request_timeout_seconds, diff --git a/posthog/request.py b/posthog/request.py index 8680c83e5..2b97872f4 100644 --- a/posthog/request.py +++ b/posthog/request.py @@ -132,12 +132,16 @@ def flags( def remote_config( - personal_api_key: str, host: Optional[str] = None, key: str = "", timeout: int = 15 + personal_api_key: str, + project_api_key: str, + host: Optional[str] = None, + key: str = "", + timeout: int = 15, ) -> Any: """Get remote config flag value from remote_config API endpoint""" return get( personal_api_key, - f"/api/projects/@current/feature_flags/{key}/remote_config/", + f"/api/projects/@current/feature_flags/{key}/remote_config?token={project_api_key}", host, timeout, ) diff --git a/posthog/test/test_client.py b/posthog/test/test_client.py index c9507e054..5e9328e2e 100644 --- a/posthog/test/test_client.py +++ b/posthog/test/test_client.py @@ -2,13 +2,13 @@ import unittest from datetime import datetime from uuid import uuid4 -from posthog.contexts import get_context_session_id, set_context_session, new_context import mock import six from parameterized import parameterized from posthog.client import Client +from posthog.contexts import get_context_session_id, new_context, set_context_session from posthog.request import APIError from posthog.test.test_utils import FAKE_TEST_API_KEY from posthog.types import FeatureFlag, LegacyFlagMetadata @@ -2057,7 +2057,7 @@ def test_set_context_session_with_page_explicit_properties(self): def test_set_context_session_override_in_capture(self): """Test that explicit session ID overrides context session ID in capture""" - from posthog.contexts import set_context_session, new_context + from posthog.contexts import new_context, set_context_session with mock.patch("posthog.client.batch_post") as mock_post: client = Client(FAKE_TEST_API_KEY, on_error=self.set_fail, sync_mode=True) @@ -2158,6 +2158,7 @@ def test_get_remote_config_payload_works_without_poller(self, patch_remote_confi self.assertEqual(result, {"test": "payload"}) patch_remote_config.assert_called_once_with( "test-personal-key", + FAKE_TEST_API_KEY, client.host, "test-flag", timeout=client.feature_flags_request_timeout_seconds, @@ -2282,9 +2283,7 @@ def test_get_feature_flag_result_with_empty_string_payload(self, patch_batch_pos } ] }, - "payloads": { - "empty-variant": "" # Empty string payload - }, + "payloads": {"empty-variant": ""}, # Empty string payload }, } ] diff --git a/posthog/version.py b/posthog/version.py index d17cba7e3..d66a32095 100644 --- a/posthog/version.py +++ b/posthog/version.py @@ -1,4 +1,4 @@ -VERSION = "6.4.0" +VERSION = "6.4.1" if __name__ == "__main__": print(VERSION, end="") # noqa: T201 diff --git a/remote_config_example.py b/remote_config_example.py new file mode 100644 index 000000000..ec5506fea --- /dev/null +++ b/remote_config_example.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +""" +Simple test script for PostHog remote config endpoint. +""" + +import posthog + +# Initialize PostHog client +posthog.api_key = "phc_..." +posthog.personal_api_key = "phs_..." # or "phx_..." +posthog.host = "http://localhost:8000" # or "https://us.posthog.com" +posthog.debug = True + + +def test_remote_config(): + """Test remote config payload retrieval.""" + print("Testing remote config endpoint...") + + # Test feature flag key - replace with an actual flag key from your project + flag_key = "unencrypted-remote-config-setting" + + try: + # Get remote config payload + payload = posthog.get_remote_config_payload(flag_key) + print(f"✅ Success! Remote config payload for '{flag_key}': {payload}") + + except Exception as e: + print(f"❌ Error getting remote config: {e}") + + +if __name__ == "__main__": + test_remote_config()