: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
chore: co-locate breakdown constants and property helpers (#56904)
Thomas Obermüllercb67c8fa3553
diff --git a/ee/hogai/context/insight/format/utils.py b/ee/hogai/context/insight/format/utils.pyindex e027e50ebd6f..c540302aa49f 100644--- a/ee/hogai/context/insight/format/utils.py+++ b/ee/hogai/context/insight/format/utils.py@@ -2,7 +2,7 @@ import datetimefrom math import floorfrom typing import Any, Optional, Union-from posthog.hogql_queries.insights.trends.breakdown import (+from posthog.hogql_queries.insights.utils.breakdowns import (BREAKDOWN_NULL_DISPLAY,BREAKDOWN_NULL_STRING_LABEL,BREAKDOWN_OTHER_DISPLAY,diff --git a/frontend/src/scenes/insights/utils.tsx b/frontend/src/scenes/insights/utils.tsxindex 0183ae99adbf..1e4ce7900f42 100644--- a/frontend/src/scenes/insights/utils.tsx+++ b/frontend/src/scenes/insights/utils.tsx@@ -323,7 +323,7 @@ function formatNumericBreakdownLabel(return String(breakdown_value)}-// Keep in sync with NOT_IN_COHORT_ID in posthog/queries/breakdown_props.py+// Keep in sync with NOT_IN_COHORT_ID in posthog/hogql_queries/insights/utils/breakdowns.pyexport const NOT_IN_COHORT_ID = 2 ** 52export function getCohortNameFromId(diff --git a/posthog/hogql_queries/experiments/breakdown_injector.py b/posthog/hogql_queries/experiments/breakdown_injector.pyindex 134fd0f931fb..b872ddc107da 100644--- a/posthog/hogql_queries/experiments/breakdown_injector.py+++ b/posthog/hogql_queries/experiments/breakdown_injector.py@@ -21,9 +21,7 @@ from posthog.hogql import astfrom posthog.hogql.parser import parse_exprfrom posthog.hogql_queries.insights.trends.utils import get_properties_chain--# Constant for representing NULL breakdown values-BREAKDOWN_NULL_STRING_LABEL = "$$_posthog_breakdown_null_$$"+from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_NULL_STRING_LABELclass BreakdownInjector:diff --git a/posthog/hogql_queries/experiments/test/experiment_query_runner/test_breakdown.py b/posthog/hogql_queries/experiments/test/experiment_query_runner/test_breakdown.pyindex ed03259445e9..39fb8719be30 100644--- a/posthog/hogql_queries/experiments/test/experiment_query_runner/test_breakdown.py+++ b/posthog/hogql_queries/experiments/test/experiment_query_runner/test_breakdown.py@@ -26,9 +26,9 @@ from posthog.schema import (StepOrderValue,)-from posthog.hogql_queries.experiments.breakdown_injector import BREAKDOWN_NULL_STRING_LABELfrom posthog.hogql_queries.experiments.experiment_query_runner import ExperimentQueryRunnerfrom posthog.hogql_queries.experiments.test.experiment_query_runner.base import ExperimentQueryRunnerBaseTest+from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_NULL_STRING_LABEL@override_settings(IN_UNIT_TESTING=True)diff --git a/posthog/hogql_queries/experiments/test/test_experiment_utils.py b/posthog/hogql_queries/experiments/test/test_experiment_utils.pyindex 0f318efd4845..94b55b403026 100644--- a/posthog/hogql_queries/experiments/test/test_experiment_utils.py+++ b/posthog/hogql_queries/experiments/test/test_experiment_utils.py@@ -17,7 +17,6 @@ from posthog.schema import (StartHandling,)-from posthog.hogql_queries.experiments.breakdown_injector import BREAKDOWN_NULL_STRING_LABELfrom posthog.hogql_queries.experiments.utils import (aggregate_variants_across_breakdowns,get_experiment_query_debug,@@ -25,6 +24,7 @@ from posthog.hogql_queries.experiments.utils import (get_variant_results,validate_variant_result,)+from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_NULL_STRING_LABELdef _columns_for(diff --git a/posthog/hogql_queries/insights/funnels/base.py b/posthog/hogql_queries/insights/funnels/base.pyindex bdf1cb151b32..a372b375ebb8 100644--- a/posthog/hogql_queries/insights/funnels/base.py+++ b/posthog/hogql_queries/insights/funnels/base.py@@ -23,11 +23,12 @@ from posthog.clickhouse.materialized_columns import ColumnNamefrom posthog.hogql_queries.insights.funnels.funnel_event_query import FunnelEventQueryfrom posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContextfrom posthog.hogql_queries.insights.funnels.utils import funnel_window_interval_unit_to_sql+from posthog.hogql_queries.insights.utils.breakdowns import ALL_USERS_COHORT_IDfrom posthog.hogql_queries.insights.utils.entities import is_equal, is_supersetfrom posthog.models.action.action import Actionfrom posthog.models.cohort.cohort import Cohortfrom posthog.models.property.property import PropertyName-from posthog.queries.breakdown_props import ALL_USERS_COHORT_ID, get_breakdown_cohort_name+from posthog.queries.breakdown_props import get_breakdown_cohort_namefrom posthog.queries.util import correct_result_for_samplingfrom posthog.types import FunnelEntityNodediff --git a/posthog/hogql_queries/insights/funnels/funnel.py b/posthog/hogql_queries/insights/funnels/funnel.pyindex 1c0d1cfa985c..b99e780f7c29 100644--- a/posthog/hogql_queries/insights/funnels/funnel.py+++ b/posthog/hogql_queries/insights/funnels/funnel.py@@ -10,7 +10,8 @@ from posthog.hogql.parser import parse_expr, parse_selectfrom posthog.hogql_queries.insights.funnels.base import JOIN_ALGOS, FunnelBasefrom posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext-from posthog.queries.breakdown_props import NOT_IN_COHORT_ID, get_breakdown_cohort_name+from posthog.hogql_queries.insights.utils.breakdowns import NOT_IN_COHORT_ID+from posthog.queries.breakdown_props import get_breakdown_cohort_namefrom posthog.utils import DATERANGE_MAPdiff --git a/posthog/hogql_queries/insights/funnels/funnel_event_query.py b/posthog/hogql_queries/insights/funnels/funnel_event_query.pyindex c35a8ba5cdf2..ae7687c968f9 100644--- a/posthog/hogql_queries/insights/funnels/funnel_event_query.py+++ b/posthog/hogql_queries/insights/funnels/funnel_event_query.py@@ -36,13 +36,12 @@ from posthog.hogql_queries.insights.funnels.utils import (entity_config_mismatch,get_breakdown_expr,)-from posthog.hogql_queries.insights.utils.breakdowns import strip_user_aliases+from posthog.hogql_queries.insights.utils.breakdowns import NOT_IN_COHORT_ID, strip_user_aliasesfrom posthog.hogql_queries.insights.utils.data_warehouse_schema_mixin import DataWarehouseSchemaMixinfrom posthog.hogql_queries.insights.utils.properties import Propertiesfrom posthog.hogql_queries.utils.query_date_range import QueryDateRangefrom posthog.models.action.action import Actionfrom posthog.models.property.property import PropertyName-from posthog.queries.breakdown_props import NOT_IN_COHORT_IDfrom posthog.types import FunnelEntityNode, FunnelExclusionEntityNodediff --git a/posthog/hogql_queries/insights/funnels/funnel_trends.py b/posthog/hogql_queries/insights/funnels/funnel_trends.pyindex 5f4a54e1a1d7..114aaa8bbeac 100644--- a/posthog/hogql_queries/insights/funnels/funnel_trends.py+++ b/posthog/hogql_queries/insights/funnels/funnel_trends.py@@ -13,10 +13,11 @@ from posthog.hogql.parser import parse_expr, parse_selectfrom posthog.hogql_queries.insights.funnels.base import JOIN_ALGOS, FunnelBasefrom posthog.hogql_queries.insights.funnels.funnel import FunnelUDF, FunnelUDFMixinfrom posthog.hogql_queries.insights.funnels.funnel_query_context import FunnelQueryContext+from posthog.hogql_queries.insights.utils.breakdowns import NOT_IN_COHORT_IDfrom posthog.hogql_queries.insights.utils.utils import get_start_of_interval_hogql, get_start_of_interval_hogql_strfrom posthog.hogql_queries.utils.query_date_range import QueryDateRangefrom posthog.hogql_queries.utils.timestamp_utils import format_label_date-from posthog.queries.breakdown_props import NOT_IN_COHORT_ID, get_breakdown_cohort_name+from posthog.queries.breakdown_props import get_breakdown_cohort_namefrom posthog.queries.util import correct_result_for_sampling, get_earliest_timestamp, get_interval_func_chfrom posthog.utils import DATERANGE_MAP, relative_date_parsediff --git a/posthog/hogql_queries/insights/funnels/test/breakdown_cases.py b/posthog/hogql_queries/insights/funnels/test/breakdown_cases.pyindex e8a353000229..01c5230fcb53 100644--- a/posthog/hogql_queries/insights/funnels/test/breakdown_cases.py+++ b/posthog/hogql_queries/insights/funnels/test/breakdown_cases.py@@ -35,10 +35,10 @@ from posthog.schema import (from posthog.constants import FunnelOrderTypefrom posthog.hogql_queries.insights.funnels.funnels_query_runner import FunnelsQueryRunnerfrom posthog.hogql_queries.insights.funnels.test.test_funnel_persons import get_actors+from posthog.hogql_queries.insights.utils.breakdowns import ALL_USERS_COHORT_ID, NOT_IN_COHORT_IDfrom posthog.models.cohort import Cohortfrom posthog.models.group.util import create_groupfrom posthog.models.instance_setting import override_instance_config-from posthog.queries.breakdown_props import ALL_USERS_COHORT_ID, NOT_IN_COHORT_IDfrom posthog.test.test_journeys import journeys_forfrom posthog.test.test_utils import create_group_type_mapping_without_created_atdiff --git a/posthog/hogql_queries/insights/retention/retention_base_query_fixed.py b/posthog/hogql_queries/insights/retention/retention_base_query_fixed.pyindex f94f20215b9b..8c2775f71f91 100644--- a/posthog/hogql_queries/insights/retention/retention_base_query_fixed.py+++ b/posthog/hogql_queries/insights/retention/retention_base_query_fixed.py@@ -7,7 +7,7 @@ from posthog.hogql.parser import parse_exprfrom posthog.hogql.property import property_to_exprfrom posthog.hogql_queries.insights.retention.retention_base_query_builder import RetentionBaseQueryBuilder-from posthog.queries.breakdown_props import ALL_USERS_COHORT_ID+from posthog.hogql_queries.insights.utils.breakdowns import ALL_USERS_COHORT_IDclass RetentionFixedIntervalBaseQueryBuilder(RetentionBaseQueryBuilder):diff --git a/posthog/hogql_queries/insights/retention/retention_query_runner.py b/posthog/hogql_queries/insights/retention/retention_query_runner.pyindex 8e659ca6f5ec..e3eb751d70fa 100644--- a/posthog/hogql_queries/insights/retention/retention_query_runner.py+++ b/posthog/hogql_queries/insights/retention/retention_query_runner.py@@ -38,9 +38,13 @@ from posthog.hogql_queries.insights.retention.retention_base_query_rolling imporRetentionRollingIntervalBaseQueryBuilder,)from posthog.hogql_queries.insights.retention.retention_validation_rules import DisallowCumulativeWith24HourWindows-from posthog.hogql_queries.insights.retention.utils import has_cohort_property-from posthog.hogql_queries.insights.trends.breakdown import BREAKDOWN_OTHER_STRING_LABEL-from posthog.hogql_queries.insights.utils.breakdowns import has_breakdown_filter, has_single_breakdown+from posthog.hogql_queries.insights.utils.breakdowns import (+ ALL_USERS_COHORT_ID,+ BREAKDOWN_OTHER_STRING_LABEL,+ has_breakdown_filter,+ has_single_breakdown,+)+from posthog.hogql_queries.insights.utils.properties import has_cohort_propertyfrom posthog.hogql_queries.query_runner import AnalyticsQueryRunnerfrom posthog.hogql_queries.utils.query_date_range import QueryDateRangeWithIntervalsfrom posthog.hogql_queries.validation.rules import DisallowUnsupportedDataWarehouseSettings@@ -48,7 +52,6 @@ from posthog.hogql_queries.validation.validation import QueryValidationRulefrom posthog.models import Teamfrom posthog.models.action.action import Actionfrom posthog.models.filters.mixins.utils import cached_property-from posthog.queries.breakdown_props import ALL_USERS_COHORT_IDfrom posthog.queries.util import correct_result_for_samplingDEFAULT_INTERVAL = IntervalType("day")diff --git a/posthog/hogql_queries/insights/retention/test/test_retention_query_runner.py b/posthog/hogql_queries/insights/retention/test/test_retention_query_runner.pyindex 94fcc50511d8..8494e514abd2 100644--- a/posthog/hogql_queries/insights/retention/test/test_retention_query_runner.py+++ b/posthog/hogql_queries/insights/retention/test/test_retention_query_runner.py@@ -36,11 +36,10 @@ from posthog.constants import (from posthog.hogql_queries.actors_query_runner import ActorsQueryRunnerfrom posthog.hogql_queries.insights.retention.retention_query_runner import RetentionQueryRunnerfrom posthog.hogql_queries.insights.retention.test.utils import pad, pluck-from posthog.hogql_queries.insights.trends.breakdown import BREAKDOWN_OTHER_STRING_LABEL+from posthog.hogql_queries.insights.utils.breakdowns import ALL_USERS_COHORT_ID, BREAKDOWN_OTHER_STRING_LABELfrom posthog.models import Action, Cohortfrom posthog.models.group.util import create_groupfrom posthog.models.person import Person-from posthog.queries.breakdown_props import ALL_USERS_COHORT_IDfrom posthog.settings import HOGQL_INCREASED_MAX_EXECUTION_TIMEfrom posthog.test.test_utils import create_group_type_mapping_without_created_atdiff --git a/posthog/hogql_queries/insights/retention/utils.py b/posthog/hogql_queries/insights/retention/utils.pyindex 0f39520eb302..38ac6b95c43f 100644--- a/posthog/hogql_queries/insights/retention/utils.py+++ b/posthog/hogql_queries/insights/retention/utils.py@@ -3,28 +3,6 @@ from typing import castfrom posthog.hogql import ast-def has_cohort_property(properties: object) -> bool:- """Recursively check if properties contain cohort filters."""- if isinstance(properties, list):- for prop in properties:- if has_cohort_property(prop):- return True- elif isinstance(properties, dict):- if properties.get("type") == "cohort":- return True- # Check nested property groups- if "values" in properties:- return has_cohort_property(properties["values"])- elif getattr(properties, "type", None) == "cohort":- return True- else:- property_values = getattr(properties, "values", None)- if property_values is not None:- return has_cohort_property(property_values)-- return False--def breakdown_extract_expr(property_name: str, breakdown_type: str, group_type_index: int | None = None) -> ast.Expr:if breakdown_type == "cohort":# For cohort breakdowns, filtering is handled in the WHERE clausediff --git a/posthog/hogql_queries/insights/trends/breakdown.py b/posthog/hogql_queries/insights/trends/breakdown.pyindex 88e442a29a56..c7e8b94b891e 100644--- a/posthog/hogql_queries/insights/trends/breakdown.py+++ b/posthog/hogql_queries/insights/trends/breakdown.py@@ -24,6 +24,9 @@ from posthog.hogql.timings import HogQLTimingsfrom posthog.hogql_queries.insights.trends.display import TrendsDisplayfrom posthog.hogql_queries.insights.trends.utils import get_properties_chainfrom posthog.hogql_queries.insights.utils.breakdowns import (+ BREAKDOWN_NULL_STRING_LABEL,+ BREAKDOWN_NUMERIC_ALL_VALUES_PLACEHOLDER,+ BREAKDOWN_OTHER_STRING_LABEL,has_breakdown_filter,has_multi_breakdown,strip_user_aliases,@@ -32,12 +35,6 @@ from posthog.hogql_queries.utils.query_date_range import QueryDateRangefrom posthog.models.filters.mixins.utils import cached_propertyfrom posthog.models.team.team import Team-BREAKDOWN_OTHER_STRING_LABEL = "$$_posthog_breakdown_other_$$"-BREAKDOWN_NULL_STRING_LABEL = "$$_posthog_breakdown_null_$$"-BREAKDOWN_OTHER_DISPLAY = "Other (i.e. all remaining values)"-BREAKDOWN_NULL_DISPLAY = "None (i.e. no value)"-BREAKDOWN_NUMERIC_ALL_VALUES_PLACEHOLDER = '["",""]'-def hogql_to_string(expr: ast.Expr) -> ast.Call:return ast.Call(name="toString", args=[expr])diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_breakdown_empty_null_properties.py b/posthog/hogql_queries/insights/trends/test/test_trends_breakdown_empty_null_properties.pyindex 7a878b26d680..357be48f3dc4 100644--- a/posthog/hogql_queries/insights/trends/test/test_trends_breakdown_empty_null_properties.py+++ b/posthog/hogql_queries/insights/trends/test/test_trends_breakdown_empty_null_properties.py@@ -24,8 +24,8 @@ from posthog.schema import ()from posthog.hogql_queries.actors_query_runner import ActorsQueryRunner-from posthog.hogql_queries.insights.trends.breakdown import BREAKDOWN_NULL_STRING_LABELfrom posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQueryRunner+from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_NULL_STRING_LABEL@override_settings(IN_UNIT_TESTING=True)diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_persons.py b/posthog/hogql_queries/insights/trends/test/test_trends_persons.pyindex 0b7934791084..b7fb6a2b8ec2 100644--- a/posthog/hogql_queries/insights/trends/test/test_trends_persons.py+++ b/posthog/hogql_queries/insights/trends/test/test_trends_persons.py@@ -36,7 +36,7 @@ from posthog.schema import (from posthog.api.test.test_team import create_teamfrom posthog.hogql_queries.actors_query_runner import ActorsQueryRunner-from posthog.hogql_queries.insights.trends.breakdown import BREAKDOWN_NULL_STRING_LABEL, BREAKDOWN_OTHER_STRING_LABEL+from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_NULL_STRING_LABEL, BREAKDOWN_OTHER_STRING_LABELfrom posthog.models import Cohort, Teamfrom posthog.models.action.action import Actionfrom posthog.models.group.util import create_groupdiff --git a/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py b/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.pyindex a2d3fa89fd59..ef264de68a1b 100644--- a/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py+++ b/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py@@ -62,12 +62,13 @@ from posthog.hogql.modifiers import create_default_modifiers_for_teamfrom posthog.hogql.query import execute_hogql_queryfrom posthog.clickhouse.client.execute import sync_execute-from posthog.hogql_queries.insights.trends.breakdown import (+from posthog.hogql_queries.insights.trends.trends_query_runner import TrendsQueryRunner+from posthog.hogql_queries.insights.utils.breakdowns import (BREAKDOWN_NULL_DISPLAY,BREAKDOWN_NULL_STRING_LABEL,+ BREAKDOWN_OTHER_DISPLAY,BREAKDOWN_OTHER_STRING_LABEL,)-from posthog.hogql_queries.insights.trends.trends_query_runner import BREAKDOWN_OTHER_DISPLAY, TrendsQueryRunnerfrom posthog.models.action.action import Actionfrom posthog.models.cohort.cohort import Cohortfrom posthog.models.group.util import create_groupdiff --git a/posthog/hogql_queries/insights/trends/trends_query_builder.py b/posthog/hogql_queries/insights/trends/trends_query_builder.pyindex 809d947f1b62..0dc0a2637916 100644--- a/posthog/hogql_queries/insights/trends/trends_query_builder.py+++ b/posthog/hogql_queries/insights/trends/trends_query_builder.py@@ -21,13 +21,10 @@ from posthog.hogql.timings import HogQLTimingsfrom posthog.hogql_queries.insights.data_warehouse_mixin import DataWarehouseInsightQueryMixinfrom posthog.hogql_queries.insights.trends.aggregation_operations import AggregationOperations-from posthog.hogql_queries.insights.trends.breakdown import (- BREAKDOWN_NULL_STRING_LABEL,- BREAKDOWN_OTHER_STRING_LABEL,- Breakdown,-)+from posthog.hogql_queries.insights.trends.breakdown import Breakdownfrom posthog.hogql_queries.insights.trends.display import TrendsDisplayfrom posthog.hogql_queries.insights.trends.utils import group_node_to_expr, is_groups_math+from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_NULL_STRING_LABEL, BREAKDOWN_OTHER_STRING_LABELfrom posthog.hogql_queries.utils.query_date_range import QueryDateRangefrom posthog.models.action.action import Actionfrom posthog.models.filters.mixins.utils import cached_propertydiff --git a/posthog/hogql_queries/insights/trends/trends_query_runner.py b/posthog/hogql_queries/insights/trends/trends_query_runner.pyindex f0a7e9ad6b03..d3ecdb68ac65 100644--- a/posthog/hogql_queries/insights/trends/trends_query_runner.py+++ b/posthog/hogql_queries/insights/trends/trends_query_runner.py@@ -54,19 +54,19 @@ from posthog.caching.insights_api import ()from posthog.clickhouse import query_taggingfrom posthog.clickhouse.query_tagging import QueryTags-from posthog.hogql_queries.insights.trends.breakdown import (+from posthog.hogql_queries.insights.trends.display import TrendsDisplay+from posthog.hogql_queries.insights.trends.series_with_extras import SeriesWithExtras+from posthog.hogql_queries.insights.trends.trend_validation_rules import ValidateDataWarehouseBreakdown+from posthog.hogql_queries.insights.trends.trends_actors_query_builder import TrendsActorsQueryBuilder+from posthog.hogql_queries.insights.trends.trends_query_builder import TrendsQueryBuilder+from posthog.hogql_queries.insights.utils.breakdowns import (BREAKDOWN_NULL_DISPLAY,BREAKDOWN_NULL_STRING_LABEL,BREAKDOWN_NUMERIC_ALL_VALUES_PLACEHOLDER,BREAKDOWN_OTHER_DISPLAY,BREAKDOWN_OTHER_STRING_LABEL,+ has_breakdown_filter,)-from posthog.hogql_queries.insights.trends.display import TrendsDisplay-from posthog.hogql_queries.insights.trends.series_with_extras import SeriesWithExtras-from posthog.hogql_queries.insights.trends.trend_validation_rules import ValidateDataWarehouseBreakdown-from posthog.hogql_queries.insights.trends.trends_actors_query_builder import TrendsActorsQueryBuilder-from posthog.hogql_queries.insights.trends.trends_query_builder import TrendsQueryBuilder-from posthog.hogql_queries.insights.utils.breakdowns import has_breakdown_filterfrom posthog.hogql_queries.insights.utils.utils import get_response_hogqlfrom posthog.hogql_queries.query_runner import AnalyticsQueryRunnerfrom posthog.hogql_queries.utils.formula_ast import FormulaASTdiff --git a/posthog/hogql_queries/insights/utils/breakdowns.py b/posthog/hogql_queries/insights/utils/breakdowns.pyindex 603a56062d09..8fa6cd539368 100644--- a/posthog/hogql_queries/insights/utils/breakdowns.py+++ b/posthog/hogql_queries/insights/utils/breakdowns.py@@ -3,6 +3,16 @@ from posthog.schema import BreakdownFilterfrom posthog.hogql import astfrom posthog.hogql.visitor import CloningVisitor+BREAKDOWN_OTHER_STRING_LABEL = "$$_posthog_breakdown_other_$$"+BREAKDOWN_NULL_STRING_LABEL = "$$_posthog_breakdown_null_$$"+BREAKDOWN_OTHER_DISPLAY = "Other (i.e. all remaining values)"+BREAKDOWN_NULL_DISPLAY = "None (i.e. no value)"+BREAKDOWN_NUMERIC_ALL_VALUES_PLACEHOLDER = '["",""]'++ALL_USERS_COHORT_ID = 0+# Keep in sync with NOT_IN_COHORT_ID in frontend/src/scenes/insights/utils.tsx+NOT_IN_COHORT_ID = 2**52+class _AliasStripper(CloningVisitor):def visit_alias(self, node: ast.Alias) -> ast.Expr:diff --git a/posthog/hogql_queries/insights/utils/properties.py b/posthog/hogql_queries/insights/utils/properties.pyindex 3e0644b869fa..2974364669cd 100644--- a/posthog/hogql_queries/insights/utils/properties.py+++ b/posthog/hogql_queries/insights/utils/properties.py@@ -34,6 +34,28 @@ def has_any_property_filters_in_group(group: PropertyGroupFilterValue) -> bool:return False+def has_cohort_property(properties: object) -> bool:+ """Recursively check if properties contain cohort filters."""+ if isinstance(properties, list):+ for prop in properties:+ if has_cohort_property(prop):+ return True+ elif isinstance(properties, dict):+ if properties.get("type") == "cohort":+ return True+ # Check nested property groups+ if "values" in properties:+ return has_cohort_property(properties["values"])+ elif getattr(properties, "type", None) == "cohort":+ return True+ else:+ property_values = getattr(properties, "values", None)+ if property_values is not None:+ return has_cohort_property(property_values)++ return False++class Properties:context: QueryContextdiff --git a/posthog/queries/breakdown_props.py b/posthog/queries/breakdown_props.pyindex b4674d4ab310..cc0a7b68b9e8 100644--- a/posthog/queries/breakdown_props.py+++ b/posthog/queries/breakdown_props.py@@ -7,6 +7,7 @@ from posthog.schema import PersonsOnEventsModefrom posthog.hogql.hogql import HogQLContextfrom posthog.constants import BREAKDOWN_TYPES, MONTHLY_ACTIVE, WEEKLY_ACTIVE, PropertyOperatorType+from posthog.hogql_queries.insights.utils.breakdowns import ALL_USERS_COHORT_ID, NOT_IN_COHORT_IDfrom posthog.models.cohort import Cohortfrom posthog.models.cohort.util import format_filter_queryfrom posthog.models.entity import Entity@@ -31,10 +32,6 @@ from posthog.queries.trends.sql import HISTOGRAM_ELEMENTS_ARRAY_OF_KEY_SQL, TOP_from posthog.queries.util import PersonPropertiesMode, alias_poe_mode_for_legacyfrom posthog.session_recordings.queries.session_query import SessionQuery-ALL_USERS_COHORT_ID = 0-# Keep in sync with NOT_IN_COHORT_ID in frontend/src/scenes/insights/utils.tsx-NOT_IN_COHORT_ID = 2**52-def get_breakdown_prop_values(filter: Filter,diff --git a/posthog/tasks/exports/csv_exporter.py b/posthog/tasks/exports/csv_exporter.pyindex 176b4f498e25..f1b965894a2a 100644--- a/posthog/tasks/exports/csv_exporter.py+++ b/posthog/tasks/exports/csv_exporter.py@@ -33,7 +33,7 @@ from posthog.utils import absolute_urifrom ...exceptions import ClickHouseQuerySizeExceededfrom ...hogql.constants import CSV_EXPORT_BREAKDOWN_LIMIT_INITIAL, CSV_EXPORT_BREAKDOWN_LIMIT_LOW, CSV_EXPORT_LIMITfrom ...hogql.query import LimitContext-from ...hogql_queries.insights.trends.breakdown import (+from ...hogql_queries.insights.utils.breakdowns import (BREAKDOWN_NULL_DISPLAY,BREAKDOWN_NULL_STRING_LABEL,BREAKDOWN_OTHER_DISPLAY,diff --git a/products/endpoints/backend/api.py b/products/endpoints/backend/api.pyindex dcbf8c04a862..1582b9d3d7d8 100644--- a/products/endpoints/backend/api.py+++ b/products/endpoints/backend/api.py@@ -65,7 +65,7 @@ from posthog.errors import ExposedCHQueryErrorfrom posthog.event_usage import get_request_analytics_properties, report_user_actionfrom posthog.exceptions_capture import capture_exceptionfrom posthog.hogql_queries.hogql_query_runner import HogQLQueryRunner-from posthog.hogql_queries.insights.trends.breakdown import BREAKDOWN_NULL_STRING_LABEL, BREAKDOWN_OTHER_STRING_LABEL+from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_NULL_STRING_LABEL, BREAKDOWN_OTHER_STRING_LABELfrom posthog.hogql_queries.query_runner import BLOCKING_EXECUTION_MODESfrom posthog.models import Userfrom posthog.models.activity_logging.activity_log import (diff --git a/products/endpoints/backend/tests/test_endpoint_execution.py b/products/endpoints/backend/tests/test_endpoint_execution.pyindex 363117cbed89..58647961ecde 100644--- a/products/endpoints/backend/tests/test_endpoint_execution.py+++ b/products/endpoints/backend/tests/test_endpoint_execution.py@@ -1795,7 +1795,7 @@ class TestEndpointExecution(ClickhouseTestMixin, APIBaseTest):self.assertIsNone(results[1][0])def test_inline_insight_cleans_other_sentinel_and_alerts(self):- from posthog.hogql_queries.insights.trends.breakdown import BREAKDOWN_OTHER_STRING_LABEL+ from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_OTHER_STRING_LABELfor event_name in [f"event_{i}" for i in range(30)]:_create_event(diff --git a/products/endpoints/backend/tests/test_endpoint_materialization.py b/products/endpoints/backend/tests/test_endpoint_materialization.pyindex 4409f0b7ea58..ae7cca38d0bf 100644--- a/products/endpoints/backend/tests/test_endpoint_materialization.py+++ b/products/endpoints/backend/tests/test_endpoint_materialization.py@@ -1263,7 +1263,7 @@ class TestEndpointMaterialization(ClickhouseTestMixin, APIBaseTest):self.assertFalse(Node.objects.filter(team=self.team, saved_query_id=saved_query_id).exists())def test_materialization_replaces_breakdown_sentinels_in_hogql(self):- from posthog.hogql_queries.insights.trends.breakdown import (+ from posthog.hogql_queries.insights.utils.breakdowns import (BREAKDOWN_NULL_STRING_LABEL,BREAKDOWN_OTHER_STRING_LABEL,)diff --git a/products/error_tracking/backend/hogql_queries/error_tracking_breakdowns_query_runner.py b/products/error_tracking/backend/hogql_queries/error_tracking_breakdowns_query_runner.pyindex e7ca7bdb5c95..a80dec818ee8 100644--- a/products/error_tracking/backend/hogql_queries/error_tracking_breakdowns_query_runner.py+++ b/products/error_tracking/backend/hogql_queries/error_tracking_breakdowns_query_runner.py@@ -13,8 +13,8 @@ from posthog.hogql import astfrom posthog.hogql.property import property_to_exprfrom posthog.hogql.query import execute_hogql_query+from posthog.hogql_queries.insights.utils.breakdowns import BREAKDOWN_NULL_STRING_LABELfrom posthog.hogql_queries.query_runner import AnalyticsQueryRunner-from posthog.queries.trends.breakdown import BREAKDOWN_NULL_STRING_LABELfrom posthog.utils import relative_date_parselogger = structlog.get_logger(__name__)