: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(logs): force OPTIMIZED property groups for logs-cluster queries (#65383)
Frank Hamand5008ddd19154
diff --git a/posthog/hogql/printer/utils.py b/posthog/hogql/printer/utils.pyindex 9afa03ce9653..ab6292282584 100644--- a/posthog/hogql/printer/utils.py+++ b/posthog/hogql/printer/utils.py@@ -1,6 +1,6 @@from typing import TYPE_CHECKING, cast-from posthog.schema_enums import InCohortVia+from posthog.schema_enums import InCohortVia, PropertyGroupsModeif TYPE_CHECKING:from posthog.schema import HogQLQueryModifiers@@ -170,6 +170,13 @@ def prepare_ast_for_printing(collector.visit(node)context.workload = collector.get_workload()+ # LOGS-cluster tables (logs, spans, metrics) store attributes in `*_map_str/_float` Map columns, not JSON blobs.+ # Property reads only resolve to those Map columns under OPTIMIZED; otherwise they fall back to JSONExtract, which+ # errors on a Map. Force OPTIMIZED here — after workload detection, before property resolution reads the modifier —+ # so every caller (SQL panel, alerts, runners) is correct without each having to set it.+ if context.workload == Workload.LOGS and context.modifiers.propertyGroupsMode is None:+ context.modifiers.propertyGroupsMode = PropertyGroupsMode.OPTIMIZED+if context.modifiers.optimizeProjections:with context.timings.measure("projection_pushdown"):node = pushdown_projections(node, context)diff --git a/products/logs/backend/test/test_alert_check_query.py b/products/logs/backend/test/test_alert_check_query.pyindex 5feaaa87ec99..ab218cc4c11a 100644--- a/products/logs/backend/test/test_alert_check_query.py+++ b/products/logs/backend/test/test_alert_check_query.py@@ -242,6 +242,35 @@ class TestAlertCheckQuery(ClickhouseTestMixin, APIBaseTest):assert isinstance(result, AlertCheckCountResult)assert result.count > 0+ @freeze_time("2025-12-16T10:33:00Z")+ def test_raw_scan_path_log_attribute_filter(self):+ # log_attribute filters read the `attributes_map_str` Map column. This only happens with+ # propertyGroupsMode=OPTIMIZED; without it the read falls back to JSONExtract, which is+ # illegal on a Map and the query errors at execution time.+ alert = self._make_alert(+ filters={+ "filterGroup": {+ "type": "AND",+ "values": [+ {+ "type": "AND",+ "values": [+ {+ "key": "log.iostream",+ "value": "stderr",+ "operator": "exact",+ "type": "log_attribute",+ }+ ],+ }+ ],+ },+ }+ )+ result = self._make_query(alert).execute()+ assert isinstance(result, AlertCheckCountResult)+ assert result.count > 0+@freeze_time("2025-12-16T10:33:00Z")def test_empty_results_return_zero(self):alert = self._make_alert(diff --git a/products/logs/backend/test/test_logs_sql_panel.py b/products/logs/backend/test/test_logs_sql_panel.pynew file mode 100644index 000000000000..aa723f7b6ea0--- /dev/null+++ b/products/logs/backend/test/test_logs_sql_panel.py@@ -0,0 +1,20 @@+from posthog.test.base import APIBaseTest, ClickhouseTestMixin++from posthog.schema import HogQLQuery++from posthog.hogql_queries.hogql_query_runner import HogQLQueryRunner+++class TestLogsSqlPanel(ClickhouseTestMixin, APIBaseTest):+ def test_attribute_filter_uses_map_not_json(self):+ # Arbitrary HogQL from the SQL panel reads logs attributes via the `attributes_map_str` Map column.+ # This relies on the LOGS workload forcing propertyGroupsMode=OPTIMIZED; without it the read falls+ # back to JSONExtract, which is illegal on a Map and errors at execution time.+ runner = HogQLQueryRunner(+ query=HogQLQuery(query="SELECT count() FROM logs WHERE attributes.`log.iostream__str` = 'stderr'"),+ team=self.team,+ )+ response = runner.calculate()+ sql = response.clickhouse or ""+ assert "JSONExtract" not in sql+ assert "attributes_map_str" in sql