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.

fix(insights): remove hogql insights replace filters flag (#53793)

Thomas Obermüller46ce05bde201
diff --git a/posthog/api/insight.py b/posthog/api/insight.py
index 47156edbf037..9cb9633b9680 100644
--- a/posthog/api/insight.py
+++ b/posthog/api/insight.py
@@ -81,7 +81,7 @@ from posthog.hogql_queries.apply_dashboard_filters import (
apply_dashboard_filters_to_dict,
apply_dashboard_variables_to_dict,
)
-from posthog.hogql_queries.legacy_compatibility.feature_flag import get_query_method, hogql_insights_replace_filters
+from posthog.hogql_queries.legacy_compatibility.feature_flag import get_query_method
from posthog.hogql_queries.legacy_compatibility.filter_to_query import filter_to_query
from posthog.hogql_queries.query_runner import (
BLOCKING_EXECUTION_MODES,
@@ -369,9 +369,9 @@ class InsightBasicSerializer(
def to_representation(self, instance):
representation = super().to_representation(instance)
- if hogql_insights_replace_filters(instance.team) and (
- instance.query is not None or instance.query_from_filters is not None
- ):
+ representation["dashboards"] = [tile["dashboard_id"] for tile in representation["dashboard_tiles"]]
+
+ if instance.query is not None or instance.query_from_filters is not None:
representation["filters"] = {}
representation["query"] = instance.query or instance.query_from_filters
else:
@@ -951,9 +951,7 @@ class InsightSerializer(InsightBasicSerializer):
request, dashboard, list(self.context["insight_variables"])
)
- if hogql_insights_replace_filters(instance.team) and (
- instance.query is not None or instance.query_from_filters is not None
- ):
+ if instance.query is not None or instance.query_from_filters is not None:
query = instance.query or instance.query_from_filters
if (
dashboard is not None
diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.py
index 34cf25a806c8..58f892ac0958 100644
--- a/posthog/api/test/dashboards/test_dashboard.py
+++ b/posthog/api/test/dashboards/test_dashboard.py
@@ -834,7 +834,7 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
response = self.dashboard_api.get_dashboard(dashboard_id)
self.assertEqual(len(response["tiles"]), 1)
self.assertEqual(response["tiles"][0]["insight"]["name"], "some_item")
- self.assertEqual(response["tiles"][0]["insight"]["filters"]["date_from"], "-14d")
+ self.assertEqual(response["tiles"][0]["insight"]["query"]["source"]["dateRange"]["date_from"], "-14d")
item_response = self.client.get(f"/api/projects/{self.team.id}/insights/").json()
self.assertEqual(item_response["results"][0]["name"], "some_item")
@@ -1128,7 +1128,7 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
tile = response["tiles"][0]
assert tile["insight"]["id"] == insight_id
- assert tile["insight"]["filters"]["date_from"] == "-14d"
+ assert tile["insight"]["query"]["source"]["dateRange"]["date_from"] == "-14d"
def test_dashboard_filtering_on_properties(self):
dashboard_id, _ = self.dashboard_api.create_dashboard({"filters": {"date_from": "-24h"}})
@@ -1156,8 +1156,16 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
self.assertEqual(len(response["tiles"]), 1)
self.assertEqual(response["tiles"][0]["insight"]["name"], "some_item")
self.assertEqual(
- response["tiles"][0]["insight"]["filters"]["properties"],
- [{"key": "prop", "value": "val"}],
+ response["tiles"][0]["insight"]["query"]["source"]["properties"],
+ [
+ {
+ "key": "prop",
+ "label": None,
+ "operator": "exact",
+ "type": "event",
+ "value": "val",
+ }
+ ],
)
def test_dashboard_filter_is_applied_even_if_insight_is_created_before_dashboard(self):
@@ -1171,11 +1179,11 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
self.dashboard_api.add_insight_to_dashboard([dashboard_id], insight_id)
response = self.dashboard_api.get_dashboard(dashboard_id)
- self.assertEqual(response["tiles"][0]["insight"]["filters"]["date_from"], "-14d")
+ self.assertEqual(response["tiles"][0]["insight"]["query"]["source"]["dateRange"]["date_from"], "-14d")
# which doesn't change the insight's filter
response = self.dashboard_api.get_insight(insight_id)
- self.assertEqual(response["filters"]["date_from"], "-7d")
+ self.assertEqual(response["query"]["source"]["dateRange"]["date_from"], "-7d")
def test_dashboard_items_history_per_user(self):
test_user = User.objects.create_and_join(self.organization, "[email protected]", None)
@@ -1845,15 +1853,10 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
)
DashboardTile.objects.create(insight=item, dashboard=dashboard)
response = self.dashboard_api.get_dashboard(dashboard.pk)
- self.assertEqual(
- response["tiles"][0]["insight"]["filters"],
- {
- "events": [{"id": "$pageview"}],
- "insight": "TRENDS",
- "date_from": None,
- "date_to": None,
- },
- )
+ self.assertEqual(response["tiles"][0]["insight"]["filters"], {})
+ query_source = response["tiles"][0]["insight"]["query"]["source"]
+ self.assertEqual(query_source["kind"], "TrendsQuery")
+ self.assertEqual(query_source["series"][0]["event"], "$pageview")
def test_retrieve_dashboard_different_team(self):
team2 = Team.objects.create(organization=Organization.objects.create(name="a"))
diff --git a/posthog/api/test/test_insight.py b/posthog/api/test/test_insight.py
index 4993ed7fe85d..10f0f59ba8b3 100644
--- a/posthog/api/test/test_insight.py
+++ b/posthog/api/test/test_insight.py
@@ -595,7 +595,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
self.assertEqual(len(response.json()["results"]), 1)
self.assertEqual(response.json()["results"][0]["short_id"], "12345678")
- self.assertEqual(response.json()["results"][0]["filters"]["events"][0]["id"], "$pageview")
+ self.assertEqual(response.json()["results"][0]["query"]["source"]["series"][0]["event"], "$pageview")
@parameterized.expand(
[
diff --git a/posthog/hogql_queries/legacy_compatibility/feature_flag.py b/posthog/hogql_queries/legacy_compatibility/feature_flag.py
index ffbd7e127af7..4a069b6336ee 100644
--- a/posthog/hogql_queries/legacy_compatibility/feature_flag.py
+++ b/posthog/hogql_queries/legacy_compatibility/feature_flag.py
@@ -6,27 +6,6 @@ from rest_framework.request import Request
from posthog.models import Team
-def hogql_insights_replace_filters(team: Team) -> bool:
- return posthoganalytics.feature_enabled(
- "hogql-insights-replace-filters",
- str(team.uuid),
- groups={
- "organization": str(team.organization_id),
- "project": str(team.id),
- },
- group_properties={
- "organization": {
- "id": str(team.organization_id),
- },
- "project": {
- "id": str(team.id),
- },
- },
- only_evaluate_locally=True,
- send_feature_flag_events=False,
- )
-
-
def insight_api_use_legacy_queries(team: Team) -> bool:
"""
Use the legacy implementation of insight api calculation endpoints.