Skip to content

: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.

chore(insights): stop serving the dead filters payload on insights (#100751)

Thomas Obermüller454531509c4a
diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.py
index 70b8aece946b..5b7146d2e265 100644
--- a/posthog/api/test/dashboards/test_dashboard.py
+++ b/posthog/api/test/dashboards/test_dashboard.py
@@ -2488,9 +2488,6 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
response = self.dashboard_api.get_dashboard(dashboard.pk)
tile_insight = response["tiles"][0]["insight"]
self.assertIsNone(tile_insight["query"])
- # The stored filters are the definition the client converts, so they have to survive the read.
- self.assertEqual(tile_insight["filters"]["events"], [{"id": "$pageview"}])
- self.assertNotIn("insight", tile_insight["filters"])
def test_retrieve_dashboard_different_team(self):
team2 = Team.objects.create(organization=Organization.objects.create(name="a"))
@@ -3082,7 +3079,6 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
"effective_restriction_level": 21,
"favorited": False,
"filter_override_context": None,
- "filters": {},
"filters_hash": ANY,
"hasMore": None,
"id": ANY,
diff --git a/products/product_analytics/backend/presentation/insight.py b/products/product_analytics/backend/presentation/insight.py
index 4691a280c939..7c2093128e84 100644
--- a/products/product_analytics/backend/presentation/insight.py
+++ b/products/product_analytics/backend/presentation/insight.py
@@ -346,7 +346,7 @@ def _record_deprecated_dashboards_field_used(context: dict, usage: str) -> None:
).inc()
-@extend_schema_serializer(exclude_fields=["filters", "saved"], deprecate_fields=["dashboards"])
+@extend_schema_serializer(exclude_fields=["saved"], deprecate_fields=["dashboards"])
class InsightBasicSerializer(
SearchMatchTypeSerializerMixin,
TaggedItemSerializerMixin,
@@ -370,7 +370,6 @@ class InsightBasicSerializer(
"short_id",
"name",
"derived_name",
- "filters",
"query",
"dashboards",
"dashboard_tiles",
@@ -420,14 +419,8 @@ class InsightBasicSerializer(
else:
representation.pop("dashboards", None)
- if instance.query is not None:
- representation["filters"] = {}
- representation["query"] = instance.query
- else:
- representation["filters"] = instance.dashboard_filters()
-
# upgrade the query to the latest version
- representation["query"] = upgrade(representation["query"])
+ representation["query"] = upgrade(instance.query)
return representation
@@ -596,7 +589,6 @@ class InsightSerializer(InsightBasicSerializer):
"short_id",
"name",
"derived_name",
- "filters",
"query",
"order",
"deleted",
@@ -648,8 +640,6 @@ class InsightSerializer(InsightBasicSerializer):
"timezone",
"refreshing",
"is_cached",
- # A read still serves the stored filters of an insight written before queries.
- "filters",
)
def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
@@ -1239,12 +1229,8 @@ class InsightSerializer(InsightBasicSerializer):
dashboard_variables_override or {},
instance.team,
)
- representation["filters"] = {}
representation["query"] = query
else:
- representation["filters"] = instance.dashboard_filters(
- dashboard=dashboard, dashboard_filters_override=dashboard_filters_override
- )
representation["query"] = instance.get_effective_query(
dashboard=dashboard,
dashboard_filters_override=dashboard_filters_override,
diff --git a/products/product_analytics/backend/tests/api/test_insight.py b/products/product_analytics/backend/tests/api/test_insight.py
index 5a97503286a9..676c905c0224 100644
--- a/products/product_analytics/backend/tests/api/test_insight.py
+++ b/products/product_analytics/backend/tests/api/test_insight.py
@@ -713,29 +713,6 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
self.assertEqual(response.json()["results"][0]["short_id"], "12345678")
self.assertEqual(response.json()["results"][0]["query"]["source"]["series"][0]["event"], "$pageview")
- @parameterized.expand([("full", ""), ("basic", "&basic=true")])
- def test_listing_an_insight_with_only_filters_serves_them(self, _name: str, query_string: str) -> None:
- # `unique_users` is not a math value the query schema accepts, so this definition cannot be
- # expressed as a query at all. Reading it used to raise out of the serializer and fail the
- # whole list request.
- stored_filters = {"events": [{"id": "$pageview", "math": "unique_users"}]}
- Insight.objects.create(
- team=self.team,
- saved=True,
- short_id="brokenfl",
- filters=stored_filters,
- )
-
- response = self.client.get(f"/api/projects/{self.team.id}/insights/?short_id=brokenfl{query_string}")
-
- self.assertEqual(response.status_code, status.HTTP_200_OK)
- result = response.json()["results"][0]
- self.assertIsNone(result["query"])
- # The stored definition survives the read, and the absent `insight` key is not filled in:
- # the client's converter defaults it, the same way the server's converter does.
- self.assertEqual(result["filters"]["events"], stored_filters["events"])
- self.assertNotIn("insight", result["filters"])
-
@parameterized.expand(
[
("numeric_id", lambda insight: insight.id),
@@ -813,7 +790,6 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
"name",
"derived_name",
"favorited",
- "filters",
"query",
"dashboard_tiles",
"description",
diff --git a/products/product_analytics/backend/tests/api/test_insight_query.py b/products/product_analytics/backend/tests/api/test_insight_query.py
index b54cbd3f96fd..fad7dce3d82f 100644
--- a/products/product_analytics/backend/tests/api/test_insight_query.py
+++ b/products/product_analytics/backend/tests/api/test_insight_query.py
@@ -145,23 +145,6 @@ class TestInsight(ClickhouseTestMixin, LicensedTestMixin, APIBaseTest, QueryMatc
expected_status=status.HTTP_201_CREATED,
)
- def test_no_default_filters_on_insight_query(self) -> None:
- _, insight_json = self.dashboard_api.create_insight(
- {
- "name": "Insight with persons table query",
- "query": {
- "kind": "DataTableNode",
- "columns": ["person", "id", "created_at", "person.$delete"],
- "source": {
- "kind": "EventsQuery",
- "select": ["*"],
- },
- },
- },
- expected_status=status.HTTP_201_CREATED,
- )
- assert insight_json["filters"] == {}
-
def test_can_save_insights_query_to_an_insight(self) -> None:
self.dashboard_api.create_insight(
{