Repository navigation
Conversation
…SET operators String "null" values were incorrectly treated as "set" in cohort filters, causing inconsistency with regular property filters. This fix ensures both operators handle string "null" values correctly: - IS_SET: Now excludes both SQL NULL and string "null" values - IS_NOT_SET: Now includes both SQL NULL and string "null" values Fixes #29916
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.
Problem
Cohort filters using
IS_SETandIS_NOT_SEToperators have inconsistent behavior compared to other PostHog systems when handling string "null" values. Users with properties containing the literal string "null" are incorrectly included inIS_SETfilters and excluded fromIS_NOT_SETfilters, which contradicts how feature flags and other parts of PostHog handle these values.Fixes #29916
Changes
/posthog/hogql/property.py: Updated_expr_to_compare_opfunction to handle string "null" values consistently(property != NULL) AND (property != 'null')(property = NULL) OR (property = 'null') OR (NOT JSONHas(...))Behavior Truth Table
NULL(SQL NULL)"null"(string)""(empty string)"value"0falseRationale for String "null" Handling
I had concerns about treating "null" as
nullbecause it could be a valid value.However, after I looked around other code, it seems that **PostHog already treats string "null" as "not set" in other areas. For example,
Materialized Columns (existing behavior):
I think this has to do with the fact that string "null" values can arise from:
nullvalues are serialized as stringsnullas string literalsHow did you test this code?
Automated Testing
👉 Stay up-to-date with PostHog coding conventions for a smoother review.