:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogql): Accept a scalar value for in and not_in property filters (#108469)
Juraj Majerik83366eaa0a14
diff --git a/posthog/hogql/property.py b/posthog/hogql/property.pyindex 10a2191e40e3..4100b6cfe504 100644--- a/posthog/hogql/property.py+++ b/posthog/hogql/property.py@@ -833,10 +833,17 @@ def _expr_to_compare_op(right=apply_path_cleaning(ast.Constant(value=value), team),)elif operator == PropertyOperator.IN_ or operator == PropertyOperator.NOT_IN:- if not isinstance(value, list):- raise Exception("IN and NOT IN operators require a list of values")+ values: list+ if isinstance(value, list):+ values = value+ elif isinstance(value, str | int | float):+ # Stored filters sometimes carry a single scalar for IN/NOT IN (filters created via+ # the API); treat it as a one-element list, the way `exact` accepts both shapes.+ values = [value]+ else:+ raise QueryError("IN and NOT IN operators require a list of values")op = ast.CompareOperationOp.NotIn if operator == PropertyOperator.NOT_IN else ast.CompareOperationOp.In- coerced = cast(list, _coerce_numeric_value_for_string_property(value, property, team))+ coerced = cast(list, _coerce_numeric_value_for_string_property(values, property, team))return ast.CompareOperation(op=op,left=expr,diff --git a/posthog/hogql/test/test_property.py b/posthog/hogql/test/test_property.pyindex f99a3ba0fa06..d5ed013dc896 100644--- a/posthog/hogql/test/test_property.py+++ b/posthog/hogql/test/test_property.py@@ -2014,6 +2014,14 @@ class TestProperty(BaseTest):ast.Constant(value=1))+ # Filters created via the API can carry a single scalar for IN/NOT IN. Rejecting the scalar+ # fails every query that uses the stored filter, so it must compile like a one-element list.+ @parameterized.expand([("in",), ("not_in",)])+ def test_scalar_value_for_in_operator_compiles_as_single_element_list(self, operator: str):+ assert self._property_to_expr(+ {"type": "event", "key": "action", "value": "edit_video", "operator": operator}+ ) == self._property_to_expr({"type": "event", "key": "action", "value": ["edit_video"], "operator": operator})+def test_every_negative_operator_is_known(self):# A negative operator missing from operator_is_negative silently negates per element on# array properties and loses its lowercase index hint, so the name pattern pins the set.