Repository navigation
fix(flags): stringify regex properties as compact JSON - #1157
Open
luantaraschi wants to merge 1 commit into
Open
luantaraschi wants to merge 1 commit into
luantaraschi wants to merge 1 commit into
Conversation
Local regex and not_regex matching called str() on the property.
This branch has not been deployed
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
Local
regexandnot_regexmatching turns the property into a string withstr(), so non-string properties are matched against their Python repr:True,[1, 2],{'a': 1}. The flags service keeps strings as they are and serializes everything else as compact JSON (to_string_representationinrust/feature-flags/src/properties/property_matching.rs), which givestrue,[1,2]and{"a":1}. So a condition likeregex "^true$"on a boolean property is false when evaluated locally and true on the server. The local evaluator spec in PostHog/sdk-specs states the same rule, and the[1,2]row of its regex outline fails on main.The other text operators (
icontains,starts_with,ends_with) already use_value_to_string. This makesregexandnot_regexuse it as well.One behavior change: a
dateordatetimeproperty used withregexused to be matched againststr(value). It now raisesInconclusiveMatchErrorand falls back to remote evaluation, which is whaticontainsandstarts_withalready do for those types. Floats come out the same as before (1.0,1e+20).💚 How did you test it?
test_regex_stringifies_non_string_properties_as_compact_jsoncovers a list, a bool and an object, each withregexandnot_regex, plus two rows checking that the Python spellings (True,'a') no longer match. All five cases fail on main and pass with the fix. The 353 tests intest_feature_flags.pypass.ruff format --check,ruff check(0.12.2), the mypy baseline andpython -W error -c "import posthog"are clean.python:3.12-slimcontainer: 5850 passed on main, 5855 passed with this change, no failures in either.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code with Claude Opus 5.5 found this while checking posthog-python against the server scenarios in PostHog/sdk-specs, reproduced it against a local mock server, and wrote the fix and the tests. Luan directed the work.