Conversation
When a feature flag has multiple conditions and one contains a static cohort, the SDK now correctly falls back to the API instead of evaluating subsequent conditions locally and returning incorrect variants. Introduce RequiresServerEvaluation exception to distinguish between: - Missing server-side data (static cohorts) → immediate API fallback - Evaluation errors (bad regex, missing properties) → try next condition Changes: - Add RequiresServerEvaluation exception class - Update match_cohort() to throw RequiresServerEvaluation for static cohorts - Update match_property_group() to propagate RequiresServerEvaluation - Update match_feature_flag_properties() to handle both exception types - Update client.py to catch both exceptions for API fallback - Export RequiresServerEvaluation in __init__.py - Add test for multi-condition static cohort scenario All 84 feature flag tests pass.
Contributor
There was a problem hiding this comment.
Additional Comments (1)
-
posthog/feature_flags.py, line 126-141 (link)logic:
RequiresServerEvaluationisn't caught and propagated in the recursive flag dependency evaluation. If a dependent flag contains a static cohort, the exception will propagate but won't be cached inevaluation_cache, which could cause issues if the same dependency is checked again.
4 files reviewed, 1 comment
gustavohstrassburger
approved these changes
Oct 21, 2025
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.
When a feature flag has multiple conditions and one contains a static cohort, the SDK now correctly falls back to the API instead of evaluating subsequent conditions locally and returning incorrect variants.
Introduce
RequiresServerEvaluationexception to distinguish between:Changes:
RequiresServerEvaluationexception classmatch_cohort()to throwRequiresServerEvaluationfor static cohortsmatch_property_group()to propagate RequiresServerEvaluationmatch_feature_flag_properties()to handle both exception typesclient.pyto catch both exceptions for API fallbackRequiresServerEvaluationin__init__.pyFollows same pattern as Node.js SDK fix: PostHog/posthog-js#2465