fix: propagate module-level settings to default client - #793
Merged
Conversation
Contributor
posthog-python Compliance ReportDate: 2026-07-28 13:29:29 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
marandaneto
marked this pull request as ready for review
July 27, 2026 20:37
Contributor
Prompt To Fix All With AI### Issue 1
posthog/__init__.py:1175
**Blank preferred key disables capture**
When `project_api_key` contains only whitespace and `api_key` is valid, this expression selects the truthy preferred key before trimming it, producing an empty configured key and disabling the default client, so module-level events are silently dropped.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "docs: clarify module API key naming" | Re-trigger Greptile |
1 similar comment
Contributor
Prompt To Fix All With AI### Issue 1
posthog/__init__.py:1175
**Blank preferred key disables capture**
When `project_api_key` contains only whitespace and `api_key` is valid, this expression selects the truthy preferred key before trimming it, producing an empty configured key and disabling the default client, so module-level events are silently dropped.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "docs: clarify module API key naming" | Re-trigger Greptile |
ioannisj
approved these changes
Jul 28, 2026
ioannisj
left a comment
There was a problem hiding this comment.
Looks good, greptile comment caught my eye as well
marandaneto
enabled auto-merge (squash)
July 28, 2026 13:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Module-level configuration is intended to configure the lazily initialized default client, but
privacy_mode,project_root, andproject_api_keywere not propagated. In particular, settingposthog.privacy_mode = Truestill allowed AI wrappers to capture full prompts and outputs.This also clarifies the established API key naming:
project_api_keyis the preferred setting and takes precedence, whileapi_keyis the deprecated legacy alias retained for backwards compatibility. Each candidate is trimmed before precedence is applied, so a blank preferred value falls back to a valid legacy value.Fixes #768.
💚 How did you test it?
python -m pytest -q posthog/test/test_module.py posthog/test/ai/openai/test_openai.py::test_privacy_mode_global posthog/test/test_code_variables.py(186 passed)ruff format --check posthog/__init__.py posthog/test/test_module.pyruff check posthog/__init__.py posthog/test/test_module.pypython -W error -c "import posthog"📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with the Pi coding agent after validating the issue against the current source and confirming the API key naming history in issues #31 and #33 and PR #32. The API key resolution preserves the SDK's established
project_api_key or api_keyprecedence after normalizing both values, while privacy mode is re-synchronized on repeatedsetup()calls so late module-level changes take effect. A human-authored review is still required; no agent session transcript was published.