Repository navigation
fix(cohorts): exclude JSON null from is_set property filter - #66573
Charan-place wants to merge 1 commit into
Conversation
…lter
prop_filter_json_extract() used a bare JSONHas() check for the
is_set/is_not_set operators. JSONHas() only checks key presence, so a
property explicitly set to JSON null (e.g. {"email": null}) was
treated as set. This is most visible for static/precalculated cohorts
built on person properties, where a person with email: null was
incorrectly included in an 'email is set' cohort.
Require the extracted value to also be non-empty and not the literal
string 'null' for is_set, and mirror the same check for is_not_set.
Fixes PostHog#29916
|
| cases = [ | ||
| (Property(key="email", operator="is_set", value="is_set"), [0]), | ||
| (Property(key="email", operator="is_not_set", value="is_not_set"), [1, 2]), | ||
| ] | ||
|
|
||
| for property, expected_event_indexes in cases: | ||
| query, params = prop_filter_json_extract(property, 0, allow_denormalized_props=False) | ||
| uuids = sorted( | ||
| [ | ||
| str(uuid) | ||
| for (uuid,) in sync_execute( | ||
| f"SELECT uuid FROM events WHERE team_id = %(team_id)s {query}", | ||
| {"team_id": team.pk, **params}, | ||
| ) | ||
| ] | ||
| ) | ||
| expected = sorted([events[index] for index in expected_event_indexes]) | ||
| assert uuids == expected, f"operator={property.operator}" |
There was a problem hiding this comment.
Prefer
@pytest.mark.parametrize over a for loop
is_set and is_not_set run through different branches in prop_filter_json_extract, so they are genuinely distinct behaviours worth parameterising. The loop also hides the first case's failure if it crashes, and the assertion message (operator=…) only partially compensates for that. Converting to @pytest.mark.parametrize("property,expected_event_indexes", [...]) matches both the project convention and the existing test_prop_filter_json_extract_person_on_events_materialized pattern directly above.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Thanks for digging into this one — the intent is right (an explicit JSON 1. Cohorts don't go through
|
|
Reviews (2): Last reviewed commit: "fix: treat explicit JSON null as not-set..." | Re-trigger Greptile |
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the |
|
@posthog-bot Can I please get an update on this PR. Pleae mention if I have to change anything in this PR. |
|
@posthog-bot Can I please get an update on this PR. Pleae mention if I have to change anything in this PR. |
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the |
|
Hey @Charan-place did you see the comment from Thomas? Here The posthog bot there wont be able to tell you anything |
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the |
|
This PR was closed due to lack of activity. Feel free to reopen if it's still relevant. |
Problem
prop_filter_json_extract()only checked whether a JSON property key existed, not whether its value was an explicit JSONnull. So a person/event property explicitly set tonullshowed up as "is set" — andis_not_setmissed those same rows.Closes #29916
Changes
prop_filter_json_extract()sois_setexcludes an explicit JSONnull, andis_not_setincludes it — consistently on both sides.How did you test this code?
Built this with Claude (Cowork). I haven't run the Postgres/ClickHouse suite in this sandbox, so I'm not pasting fabricated pytest output — the new test exists but I haven't executed it myself.
One known gap: the new test only covers the
allow_denormalized_props=Falsepath. A reviewer on the earlier combined PR (#65069) flagged that the denormalized branch needs its own test too, and I haven't added that yet — calling it out rather than burying it.Automatic notifications
Docs update
Not needed.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Used Claude (Cowork) to track down the bug, write the fix, and add the test above. I reviewed the diff and I'm the one submitting and owning this PR.