: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): stop excludeAttributes shadowing the attributes field (#73831)
Frank Hamande255df5b768a
diff --git a/products/logs/backend/logs_query_runner.py b/products/logs/backend/logs_query_runner.pyindex 73c7ee86eac6..b7bad3239ecd 100644--- a/products/logs/backend/logs_query_runner.py+++ b/products/logs/backend/logs_query_runner.py@@ -692,10 +692,12 @@ class LogsQueryRunner(AnalyticsQueryRunner[LogsQueryResponse], LogsQueryRunnerMi"where": self.where(),"live_logs_checkpoint": LIVE_LOGS_CHECKPOINT_QUERY,# Attribute maps dominate payload size. When excluded we still SELECT a column- # (an empty map) so the positional result mapping in _calculate stays stable.- "attributes": parse_expr("map() AS attributes" if self.query.excludeAttributes else "attributes"),+ # (an empty map) so the positional result mapping in _calculate stays stable. The+ # placeholder must stay unaliased — aliasing it to `attributes`/`resource_attributes`+ # would shadow the physical field a WHERE-clause attribute filter needs to resolve.+ "attributes": parse_expr("map()" if self.query.excludeAttributes else "attributes"),"resource_attributes": parse_expr(- "map() AS resource_attributes" if self.query.excludeAttributes else "resource_attributes"+ "map()" if self.query.excludeAttributes else "resource_attributes"),},)diff --git a/products/logs/backend/test/test_exclude_attributes.py b/products/logs/backend/test/test_exclude_attributes.pyindex a25f810d7a4e..fed7aade8fee 100644--- a/products/logs/backend/test/test_exclude_attributes.py+++ b/products/logs/backend/test/test_exclude_attributes.py@@ -34,12 +34,12 @@ class TestLogsExcludeAttributes(ClickhouseTestMixin, APIBaseTest):sync_execute("TRUNCATE TABLE IF EXISTS logs32")super().tearDownClass()- def _run(self, *, exclude: bool) -> list[dict]:+ def _run(self, *, exclude: bool, filter_group: dict | None = None) -> list[dict]:query = LogsQuery(dateRange=DateRange(date_from=DATE_FROM, date_to=DATE_TO),serviceNames=["argo-rollouts"],severityLevels=[],- filterGroup={"type": "AND", "values": []},+ filterGroup=filter_group or {"type": "AND", "values": []},excludeAttributes=exclude,)return LogsQueryRunner(query, self.team).run().results@@ -60,3 +60,23 @@ class TestLogsExcludeAttributes(ClickhouseTestMixin, APIBaseTest):else:self.assertTrue(results[0]["attributes"])self.assertEqual(results[0]["resource_attributes"]["service.name"], "argo-rollouts")++ def test_value_filter_with_excluded_attributes(self):+ # Excluding attributes must not shadow the physical `attributes` field a value-comparison+ # log_attribute filter resolves against. Before the fix this raised a QueryError (400):+ # "Cannot access property 'logtag__str' on 'attributes'".+ filter_group = {+ "type": "AND",+ "values": [+ {+ "type": "AND",+ "values": [+ {"key": "logtag", "operator": "exact", "type": "log_attribute", "value": "F"},+ ],+ }+ ],+ }+ results = self._run(exclude=True, filter_group=filter_group)+ self.assertEqual(len(results), 1)+ self.assertEqual(results[0]["attributes"], {})+ self.assertEqual(results[0]["resource_attributes"], {})