Local flag evaluation drops users whose rollout context value is 0 or False - #192
Open
ckarnell wants to merge 1 commit into
Open
Local flag evaluation drops users whose rollout context value is 0 or False#192ckarnell wants to merge 1 commit into
ckarnell wants to merge 1 commit into
Conversation
A context value of 0 or False took the missing-key branch, so the user got the fallback with reason MISSING_CONTEXT_KEY and a log line saying the key was absent from a dictionary that contained it. context_value is typed Any and is only used as normalized_hash(str(...)), so falsy values bucket the same as any other.
Confidence Score: 5/5The PR appears safe to merge. The changed presence check matches the missing-key fallback semantics, and the regression tests cover the reported numeric and boolean falsy cases without disturbing absent-key handling.
|
| Filename | Overview |
|---|---|
| mixpanel/flags/local_feature_flags.py | Correctly narrows missing-context detection to None, allowing falsy values to participate in local rollout evaluation. |
| mixpanel/flags/test_local_feature_flags.py | Adds focused regression tests confirming that zero and false context values are locally evaluated. |
Reviews (1): Last reviewed commit: "Treat a falsy rollout context value as p..." | Re-trigger Greptile
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.
Local flag evaluation reads the rollout context with a truthiness check:
A context value of
0orFalsetakes the missing-key branch. The user gets the fallback, the reason attached to it isMISSING_CONTEXT_KEY, and the log reports the key as absent from a dictionary that contains it.Falsy values are legitimate here.
context_valueis typedAnyand the only thing done with it isnormalized_hash(str(context_value), salt), so0buckets as"0"the same way1buckets as"1". The docstring describes the context as the distinct_id "and any other attributes needed for rollout evaluation", and attributes like a purchase count or a subscription boolean are falsy for a large share of users.Anyone bucketed on a numeric or boolean property is excluded from every locally evaluated flag on that property, and the fallback reason points at the caller for an argument they passed.
Two tests added next to
test_get_variant_tags_missing_context, one for0and one forFalse. Both fail on master. The existing test for an absent key still passes untouched, which is the half I wanted to be sure of. Full suite 170 passed on 3.9.One judgement call worth your eyes:
is Nonemeans an empty string now counts as present and gets hashed instead of falling back. That seemed right, since the message and the reason are both about presence, but it's your call.