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(cdp): stop hiding hog functions filtered on all events (#86614)

Harley Alexander2e50b7b611a1
diff --git a/products/cdp/backend/api/hog_function.py b/products/cdp/backend/api/hog_function.py
index dc56af0ecdb1..e83cb8187733 100644
--- a/products/cdp/backend/api/hog_function.py
+++ b/products/cdp/backend/api/hog_function.py
@@ -26,11 +26,7 @@ from posthog.api.log_entries import LogEntryMixin
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import SearchMatchTypeSerializerMixin, UserBasicSerializer
from posthog.api.utils import action, log_activity_from_viewset
-from posthog.cdp.internal_events import (
- LEGACY_INSIGHT_ALERT_EVENT,
- MANAGED_ALERT_EVENT_PATTERN,
- is_managed_alert_internal_event,
-)
+from posthog.cdp.internal_events import is_managed_alert_internal_event
from posthog.cdp.services.icons import CDPIconsService
from posthog.cdp.site_functions import get_transpiled_function
from posthog.cdp.validation import (
@@ -951,12 +947,6 @@ class HogFunctionViewSet(
def safely_get_queryset(self, queryset: QuerySet) -> QuerySet:
queryset = queryset.exclude(type=HogFunctionType.WAREHOUSE_SOURCE_WEBHOOK.value)
- # Managed alert destinations are single-event by construction, so events[0] is sufficient here.
- queryset = queryset.filter(
- Q(filters__events__0__id__isnull=True)
- | Q(filters__events__0__id=LEGACY_INSIGHT_ALERT_EVENT)
- | ~Q(filters__events__0__id__regex=MANAGED_ALERT_EVENT_PATTERN)
- )
if not (self.action == "partial_update" and self.request.data.get("deleted") is False):
# We only want to include deleted functions if we are un-deleting them
diff --git a/products/cdp/backend/api/test/test_hog_function.py b/products/cdp/backend/api/test/test_hog_function.py
index 25173b7b5bd9..171a1b12a93a 100644
--- a/products/cdp/backend/api/test/test_hog_function.py
+++ b/products/cdp/backend/api/test/test_hog_function.py
@@ -227,21 +227,15 @@ class TestHogFunctionAPIWithoutAvailableFeature(ClickhouseTestMixin, APIBaseTest
listed_ids = {item["id"] for item in list_response.json()["results"]}
self.assertIn(function_id, listed_ids)
- def test_generic_api_hides_and_cannot_patch_managed_alert_destinations(self):
- ordinary = HogFunction.objects.create(
- team=self.team,
- name="Ordinary destination",
- hog="return event",
- type="destination",
- enabled=False,
- filters={},
- )
+ def test_generic_api_lists_but_cannot_patch_managed_alert_destinations(self):
managed = HogFunction.objects.create(
team=self.team,
name="Billing alert destination",
hog="return event",
type="internal_destination",
enabled=True,
+ inputs_schema=[],
+ inputs={},
filters={
"events": [{"id": "$billing_alert_firing", "type": "events"}],
"properties": [{"key": "alert_id", "value": "alert-1"}],
@@ -249,20 +243,38 @@ class TestHogFunctionAPIWithoutAvailableFeature(ClickhouseTestMixin, APIBaseTest
)
list_response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?full=true")
- ordinary_response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/{ordinary.id}/")
retrieve_response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/{managed.id}/")
patch_response = self.client.patch(
f"/api/projects/{self.team.id}/hog_functions/{managed.id}/",
- data={"inputs": {"url": {"value": "https://attacker.example"}}},
+ data={"name": "Renamed alert destination"},
)
self.assertEqual(list_response.status_code, status.HTTP_200_OK)
listed_ids = {item["id"] for item in list_response.json()["results"]}
- self.assertEqual(ordinary_response.status_code, status.HTTP_200_OK, ordinary_response.json())
- self.assertIn(str(ordinary.id), listed_ids)
- self.assertNotIn(str(managed.id), listed_ids)
- self.assertEqual(retrieve_response.status_code, status.HTTP_404_NOT_FOUND)
- self.assertEqual(patch_response.status_code, status.HTTP_404_NOT_FOUND)
+ self.assertIn(str(managed.id), listed_ids)
+ self.assertEqual(retrieve_response.status_code, status.HTTP_200_OK, retrieve_response.json())
+ self.assertEqual(patch_response.status_code, status.HTTP_400_BAD_REQUEST, patch_response.json())
+ self.assertIn("managed through the alert API", patch_response.json()["detail"])
+
+ def test_functions_filtered_on_all_events_are_listed_and_retrievable(self):
+ # An explicit "All events" filter persists as a JSON-null event id, which queryset-level
+ # JSON lookups (isnull, regex) silently miss, dropping the row from every read path.
+ function = HogFunction.objects.create(
+ team=self.team,
+ name="Drop events",
+ hog="return null",
+ type="transformation",
+ enabled=True,
+ filters={"events": [{"id": None, "name": "All events", "type": "events"}]},
+ )
+
+ list_response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?type=transformation")
+ retrieve_response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/{function.id}/")
+
+ self.assertEqual(list_response.status_code, status.HTTP_200_OK)
+ listed_ids = {item["id"] for item in list_response.json()["results"]}
+ self.assertIn(str(function.id), listed_ids)
+ self.assertEqual(retrieve_response.status_code, status.HTTP_200_OK, retrieve_response.json())
class TestHogFunctionAPI(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):