Repository navigation
fix(server): don't match person_metadata filters against person properties - #998
marandaneto merged 5 commits into
Conversation
…rties
PropertyType.fromString mapped every unknown filter type, including
person_metadata (Person metadata > First seen), to PERSON, so local
evaluation matched it against a caller's created_at person property and
could disagree with /flags, which reads the persons table.
Unknown types now parse to a new PropertyType.UNSUPPORTED ("person" and
"group" still map to PERSON). posthog-server rejects UNSUPPORTED filters
as unsupported_definition at load and during evaluation, so the flag
falls back to /flags.
Part of PostHog/posthog#137503 (posthog-server)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dustinbyrne
left a comment
There was a problem hiding this comment.
The production change in PropertyType and FlagEvaluator looks directionally right for stopping unknown filter types like person_metadata from matching caller person properties. A few items need attention before approval (details inline):
- Breaking: Updating
PropertyType.fromStringbreaks an existing:posthog:testassertion (PostHogLocalEvaluationModelsTest.testPropertyTypeFromString:389). - Concern: Key changed paths—absent-property evaluation (
UNSUPPORTED_DEFINITIONvsMISSING_CONTEXT), publicevaluateFlags(..., onlyEvaluateLocally = true)/unresolvedFlagswith cohortnegation: true, andGsonPropertyTypeAdapterserialization—lack regression tests. - Suggestion: Consider excluding explicit empty string
""fromPropertyType.PERSONto match the PostHog backend andposthog-dotnet.
Follow-up (outside this PR): Track specifying unknown filter types in PostHog/sdk-specs (local-feature-flag-evaluator/spec.md) and applying matching fixes to remaining server SDKs (posthog-python, posthog-js/packages/node) under PostHog/posthog#137503.
AI-assisted review.
Update the type parsing test for the unsupported type, treat an empty type as unsupported like /flags does, and cover evaluateFlags with nothing passed, cohorts and negation, the definition check and the cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dustinbyrne
left a comment
There was a problem hiding this comment.
Thanks for the quick follow-up in 1113f193! All three earlier review items (PostHogLocalEvaluationModelsTest.testPropertyTypeFromString, excluding "" from PropertyType.PERSON, and expanding PersonMetadataFilterTest) are addressed, and the production changes look solid.
One remaining test-reliability concern inline: the new evaluateFlags test uses createMockHttp(jsonResponse(definitions)) (my earlier sketch used that too), which races the background LocalEvaluationPoller against a single-response QueueDispatcher.
AI-assisted review.
The poller can load the definitions a second time. Route the responses by path and count the /flags calls instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marandaneto
left a comment
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
Thank you for your contribution!
💡 Motivation and Context
Part of PostHog/posthog#137503, for
posthog-server.PropertyType.fromStringmapped every unknown filter type toPERSON, includingperson_metadata(Person metadata > First seen). Local evaluation then matched it against a caller'screated_atperson property, which can disagree with/flags, since/flagsreads the persons table.PropertyType.UNSUPPORTEDfor unknown types, an empty string included."person"and"group"still map toPERSON. The class is@PostHogInternal, andapiCheckpasses forposthogandposthog-server.FlagEvaluatorrejectsUNSUPPORTEDfilters withunsupported_definition, both in the load-time definition check and during matching. That covers flag conditions and cohort criteria, and the flag falls back to/flags.The same change for the other SDKs: PostHog/posthog-js#5840, PostHog/posthog-python#1288, PostHog/posthog-go#465, PostHog/posthog-rs#397.
💚 How did you test it?
New
PersonMetadataFilterTest:personfilter oncreated_atstill matches;/flagsthroughPostHogFeatureFlagswith a mock server;PostHog.evaluateFlagsreports a condition, a cohort and a negated cohort leaf as unsupported, with and withoutcreated_at;UNSUPPORTEDsurvives a Gson round trip.PostHogLocalEvaluationModelsTest.testPropertyTypeFromStringexpects the new mapping.spotlessCheckandPersonMetadataFilterTest(8 tests) pass. The numbers below are from the commit before it.:posthog:test: 1315 tests, 0 failures.:posthog-server:test: 699 tests, 1 failure, thePostHogServerWireSnapshotTestexception snapshot, which also fails on cleanmainhere (Windows).spotlessCheckandapiCheckpass.📝 Checklist
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
364a698.🤖 Generated with Claude Code