-
Notifications
You must be signed in to change notification settings - Fork 39
fix(flags): Pass project API key in remote_config
requests
#303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR updates the remote configuration functionality in the PostHog Python SDK to align with backend API changes. The core modification switches the remote_config
function from making GET requests to POST requests, and introduces a required project_api_key
parameter for deterministic project selection and validation.
The changes span four files:
-
posthog/request.py
: Theremote_config
function is completely rewritten to use POST requests instead of GET. It now accepts aproject_api_key
parameter and includes both the personal API key (in Authorization header) and project API key (in request body) for proper authentication and project validation. -
posthog/client.py
: Theget_remote_config_payload
method is updated to passself.api_key
as theproject_api_key
parameter when calling theremote_config
function. This ensures that remote config requests include the necessary project identification. -
posthog/test/test_client.py
: Test cases are updated to expect the newproject_api_key
parameter in remote_config function calls. The test mocking is adjusted to reflect the new API signature. -
remote_config_example.py
: A new example script is added to demonstrate usage of the updated remote config functionality, showing how both project and personal API keys work together.
This change improves security by ensuring that personal API keys are properly validated against the expected project context, and provides more reliable routing for multi-project scenarios. The modification is part of a broader effort to standardize project identification across PostHog's API endpoints.
Confidence score: 2/5
- This PR has significant implementation issues that could cause production problems
- Score lowered due to anti-patterns in the request.py implementation and potential reliability concerns
- The remote_config function bypasses the configured session and retry logic, imports modules inline, and may break existing functionality
4 files reviewed, 2 comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
remote_config
requestsremote_config
and local_evaluation
requests
remote_config
and local_evaluation
requestsremote_config
requests
eea00bb
to
735bde8
Compare
2625ff5
to
29ecfbe
Compare
29ecfbe
to
19b1bcd
Compare
remote_config
requestsremote_config
requests
19b1bcd
to
b61cb20
Compare
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.
Prepare for release with remote_config project API key fix
248f195
to
5815f35
Compare
…ect routing This change ensures that remote config requests include the project API key as a query parameter, enabling deterministic project routing when using personal API keys that have access to multiple projects. Port of PostHog Python implementation: PostHog/posthog-python#303 Changes: - Update remote config URL to include token parameter with project API key - Add comprehensive test coverage for the new URL format - Update changelog to document the fix
Updates
remote_config
to pass the project api key in thetoken
query string parameter. This is the same approach taken withlocal_evaluation
. This ensures deterministic project routing.