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.

test(activity-logs): run filter serializer validation without a DB (#66712)

Paul D'Ambra39e833eea611
diff --git a/posthog/api/advanced_activity_logs/test_filters.py b/posthog/api/advanced_activity_logs/test_filters.py
index 016a41aeb377..f053e9bc0195 100644
--- a/posthog/api/advanced_activity_logs/test_filters.py
+++ b/posthog/api/advanced_activity_logs/test_filters.py
@@ -1,6 +1,7 @@
from posthog.test.base import BaseTest
from django.http import QueryDict
+from django.test import SimpleTestCase
from parameterized import parameterized
@@ -291,6 +292,11 @@ class TestIpAddressFilter(BaseTest):
filtered = self.filter_manager.apply_filters(queryset, {"ip_addresses": ["198.51.100.7", "203.0.*"]})
self.assertEqual(set(filtered.values_list("id", flat=True)), {exact_match.id, wildcard_match.id})
+
+class TestAdvancedActivityLogFiltersSerializerValidation(SimpleTestCase):
+ # Pure field-level validation (the serializer has no validate() and no context),
+ # so no DB is needed. The viewset wiring is guarded by an endpoint test in
+ # TestOrganizationAdvancedActivityLogsViewSet (test_activity_log.py).
@parameterized.expand(
[
("ipv4", "203.0.113.42", True),
diff --git a/posthog/api/test/test_activity_log.py b/posthog/api/test/test_activity_log.py
index e0b74d5e5dfc..125d96bbf26b 100644
--- a/posthog/api/test/test_activity_log.py
+++ b/posthog/api/test/test_activity_log.py
@@ -332,6 +332,13 @@ class TestOrganizationAdvancedActivityLogsViewSet(APIBaseTest):
# Cross-org row does NOT appear
assert "flag-outside" not in item_ids
+ def test_invalid_filter_is_rejected(self) -> None:
+ # Wiring guard: the viewset must run AdvancedActivityLogFiltersSerializer on the query params.
+ # The exhaustive filter-shape matrix is unit-tested without a DB in
+ # TestAdvancedActivityLogFiltersSerializerValidation (advanced_activity_logs/test_filters.py).
+ res = self._list(ip_addresses="not-an-ip")
+ assert res.status_code == status.HTTP_400_BAD_REQUEST
+
@parameterized.expand(
[
("owner", OrganizationMembership.Level.OWNER, status.HTTP_200_OK),