chore(flags): expose flag_definition_cache_provider#462
Merged
matheus-vb merged 2 commits intomasterfrom Mar 12, 2026
Merged
Conversation
Contributor
|
Last reviewed commit: 875b64b |
Contributor
posthog-python Compliance ReportDate: 2026-03-11 23:15:32 UTC ✅ All Tests Passed!29/29 tests passed Capture Tests✅ 29/29 tests passed View Details
|
Collaborator
|
The PR description mentions additional changes (stale cache fallback for failed flags in client.py, types.py, and a new test), but I don't see those in this PR. Is the PR description incorrect or did you forget to push? |
Member
Author
|
Oops those changes were supposed to be on another PR, will clean up the description |
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.
Problem
The PostHog monolith wants to use a
HyperCacheFlagProvider(see posthog#50737) to read flag definitions directly from Redis instead of polling the API every 90 seconds per worker. However, the SDK's module-level API has no way to accept an external cache provider — theflag_definition_cache_providerparameter only exists on theClientconstructor, not as a module-level variable.Solution
Module-level
flag_definition_cache_providerExpose
flag_definition_cache_provideras a module-level variable inposthog/__init__.py(matching the pattern used by all other SDK settings likepersonal_api_key,poll_interval, etc.) and pass it throughsetup()to theClientconstructor. This allows the monolith to setposthoganalytics.flag_definition_cache_provider = HyperCacheFlagProvider(...)before any flags are evaluated.Changes
posthog/__init__.pyflag_definition_cache_providermodule-level variable (defaults toNone)setup()to theClientconstructorHow did you test this code?
make test)Downstream dependency
This PR must be merged and released before posthog#50737 can land, since the monolith PR sets
posthoganalytics.flag_definition_cache_providerat startup.