: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): normalize flat filterGroup on the services endpoint (#76399)
posthog[bot]bf9d23536765
diff --git a/products/logs/backend/presentation/views/api.py b/products/logs/backend/presentation/views/api.pyindex 633abb6a4e8b..69d15f5cffeb 100644--- a/products/logs/backend/presentation/views/api.py+++ b/products/logs/backend/presentation/views/api.py@@ -16,15 +16,7 @@ from rest_framework.request import Requestfrom rest_framework.response import Responsefrom rest_framework.throttling import BaseThrottle-from posthog.schema import (- DateRange,- FilterLogicalOperator,- LogAttributesQuery,- LogsOrderBy,- LogsQuery,- LogValuesQuery,- PropertyGroupFilter,-)+from posthog.schema import DateRange, LogAttributesQuery, LogsOrderBy, LogsQuery, LogValuesQuery, PropertyGroupFilterfrom posthog.hogql.errors import QueryError@@ -1462,16 +1454,12 @@ class LogsViewSet(TeamAndOrgViewSetMixin, PydanticModelMixin, viewsets.ViewSet):tag_queries(product=Product.LOGS, feature=Feature.QUERY)query_data = request.data.get("query", {})- filter_group = query_data.get("filterGroup", None)- if filter_group is None:- filter_group = PropertyGroupFilter(type=FilterLogicalOperator.AND_, values=[])-query = LogsQuery(dateRange=self.get_model(query_data.get("dateRange"), DateRange),severityLevels=query_data.get("severityLevels", []),serviceNames=query_data.get("serviceNames", []),searchTerm=query_data.get("searchTerm", None),- filterGroup=filter_group,+ filterGroup=self._normalize_filter_group(query_data.get("filterGroup", None)),)runner = ServicesQueryRunner(team=self.team, query=query)diff --git a/products/logs/backend/test/test_services_query_runner.py b/products/logs/backend/test/test_services_query_runner.pyindex 0f811f9584eb..1f979515dc33 100644--- a/products/logs/backend/test/test_services_query_runner.py+++ b/products/logs/backend/test/test_services_query_runner.py@@ -207,6 +207,32 @@ class TestServicesQueryDateRange(ClickhouseTestMixin, APIBaseTest):self.assertEqual(windowed["services"][0]["service_name"], "cdp-legacy-events-consumer")self.assertEqual(windowed["services"][0]["log_count"], 100)+ @freeze_time("2025-12-16T10:33:00Z")+ def test_services_normalizes_flat_filter_group_from_mcp(self):+ # MCP tools send `filterGroup` as a flat list of property filters (see+ # `_normalize_filter_group`'s docstring), not the nested PropertyGroupFilter shape+ # `_services` above sends. Passing that flat shape straight to `LogsQuery` used to+ # raise an unhandled pydantic ValidationError (500) instead of running the query.+ response = self.client.post(+ f"/api/projects/{self.team.id}/logs/services",+ data={+ "query": {+ "dateRange": {"date_from": "2025-12-16T00:00:00Z", "date_to": "2025-12-16T23:59:59Z"},+ "filterGroup": [+ {+ "key": "service.name",+ "type": "log_resource_attribute",+ "operator": "exact",+ "value": "cdp-legacy-events-consumer",+ }+ ],+ }+ },+ )+ self.assertEqual(response.status_code, status.HTTP_200_OK)+ services = response.json()["services"]+ self.assertEqual({s["service_name"] for s in services}, {"cdp-legacy-events-consumer"})+@freeze_time("2025-12-16T10:33:00Z")def test_sparkline_covers_exactly_the_returned_services(self):# The sparkline must line up exactly with the aggregates result: never a