: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(error-tracking): route no-op cymbal rule filters through match-all bytecode (#60077)
Aleksander Błaszkiewicz7a2d3c1471da
diff --git a/products/error_tracking/backend/api/assignment_rules.py b/products/error_tracking/backend/api/assignment_rules.pyindex 63f1058d9565..bad56624209e 100644--- a/products/error_tracking/backend/api/assignment_rules.py+++ b/products/error_tracking/backend/api/assignment_rules.py@@ -15,7 +15,7 @@ from posthog.event_usage import groupsfrom products.error_tracking.backend.models import ErrorTrackingAssignmentRule-from .utils import RuleReorderingMixin, generate_byte_code+from .utils import RuleReorderingMixin, generate_byte_code, generate_match_all_bytecode, has_filter_valueslogger = structlog.get_logger(__name__)@@ -133,9 +133,11 @@ class ErrorTrackingAssignmentRuleViewSet(TeamAndOrgViewSetMixin, viewsets.ModelVassignee = request.validated_data.get("assignee")if json_filters:- parsed_filters = PropertyGroupFilterValue(**json_filters)assignment_rule.filters = json_filters- assignment_rule.bytecode = generate_byte_code(self.team, parsed_filters)+ if has_filter_values(json_filters):+ assignment_rule.bytecode = generate_byte_code(self.team, PropertyGroupFilterValue(**json_filters))+ else:+ assignment_rule.bytecode = generate_match_all_bytecode()if assignee:assignment_rule.user_id = None if assignee["type"] != "user" else assignee["id"]@@ -183,9 +185,10 @@ class ErrorTrackingAssignmentRuleViewSet(TeamAndOrgViewSetMixin, viewsets.ModelVjson_filters = request.validated_data["filters"]assignee = request.validated_data["assignee"]- parsed_filters = PropertyGroupFilterValue(**json_filters)-- bytecode = generate_byte_code(self.team, parsed_filters)+ if has_filter_values(json_filters):+ bytecode = generate_byte_code(self.team, PropertyGroupFilterValue(**json_filters))+ else:+ bytecode = generate_match_all_bytecode()assignment_rule = ErrorTrackingAssignmentRule.objects.create(team=self.team,diff --git a/products/error_tracking/backend/api/grouping_rules.py b/products/error_tracking/backend/api/grouping_rules.pyindex da0108c7ecc5..5ab908614bfd 100644--- a/products/error_tracking/backend/api/grouping_rules.py+++ b/products/error_tracking/backend/api/grouping_rules.py@@ -16,7 +16,7 @@ from posthog.event_usage import groupsfrom products.error_tracking.backend.models import ErrorTrackingGroupingRule, ErrorTrackingIssueFingerprintV2-from .utils import RuleReorderingMixin, generate_byte_code+from .utils import RuleReorderingMixin, generate_byte_code, has_filter_valueslogger = structlog.get_logger(__name__)@@ -32,6 +32,8 @@ class ErrorTrackingGroupingRuleFiltersField(serializers.JSONField):except PydanticValidationError as err:logger.warning("Invalid grouping rule filters payload", exc_info=err)raise serializers.ValidationError("Invalid filters payload.") from err+ if not has_filter_values(value):+ raise serializers.ValidationError("Filters must contain at least one filter value.")return valuediff --git a/products/error_tracking/backend/api/suppression_rules.py b/products/error_tracking/backend/api/suppression_rules.pyindex 8cd9ae1f9c07..69f0074d089e 100644--- a/products/error_tracking/backend/api/suppression_rules.py+++ b/products/error_tracking/backend/api/suppression_rules.py@@ -16,7 +16,7 @@ from posthog.models.team.team import Teamfrom products.error_tracking.backend.models import ErrorTrackingSuppressionRule-from .utils import RuleReorderingMixin, generate_byte_code, generate_match_all_bytecode+from .utils import RuleReorderingMixin, generate_byte_code, generate_match_all_bytecode, has_filter_valueslogger = structlog.get_logger(__name__)@@ -36,7 +36,7 @@ class ErrorTrackingSuppressionRuleFiltersField(serializers.JSONField):if not isinstance(value, dict):raise serializers.ValidationError("Expected an object.")- if _has_filter_values(value):+ if has_filter_values(value):try:PropertyGroupFilterValue(**value)except (PydanticValidationError, TypeError) as err:@@ -102,7 +102,7 @@ class ErrorTrackingSuppressionRuleViewSet(TeamAndOrgViewSetMixin, viewsets.Modeljson_filters = request.validated_data.get("filters")if json_filters is not None:- if _has_filter_values(json_filters):+ if has_filter_values(json_filters):parsed_filters = PropertyGroupFilterValue(**json_filters)suppression_rule.filters = json_filterssuppression_rule.bytecode = generate_byte_code(self.team, parsed_filters)@@ -158,7 +158,7 @@ class ErrorTrackingSuppressionRuleViewSet(TeamAndOrgViewSetMixin, viewsets.Modelif json_filters is None:json_filters = {"type": "AND", "values": []}- if _has_filter_values(json_filters):+ if has_filter_values(json_filters):bytecode = generate_byte_code(self.team, PropertyGroupFilterValue(**json_filters))else:bytecode = generate_match_all_bytecode()@@ -182,15 +182,6 @@ class ErrorTrackingSuppressionRuleViewSet(TeamAndOrgViewSetMixin, viewsets.Modelreturn Response(serializer.data, status=status.HTTP_201_CREATED)-def _has_filter_values(json_filters: dict) -> bool:- """Check whether a filter dict contains any actual filter values."""- values = json_filters.get("values", [])- if not values:- return False- # Check nested groups (the outer group wraps inner groups with actual filters)- return any(v.get("values") or "key" in v for v in values)--# Properties that require server-side symbol resolution to have meaningful# values. Client-side these will contain minified/bundled names.SERVER_ONLY_PROPERTIES = frozenset({"$exception_sources", "$exception_functions"})diff --git a/products/error_tracking/backend/api/test/test_assignment_rules.py b/products/error_tracking/backend/api/test/test_assignment_rules.pyindex 75003311aafd..d104fbd5e02e 100644--- a/products/error_tracking/backend/api/test/test_assignment_rules.py+++ b/products/error_tracking/backend/api/test/test_assignment_rules.py@@ -6,6 +6,7 @@ from posthog.test.base import APIBaseTestfrom parameterized import parameterizedfrom rest_framework import status+from products.error_tracking.backend.api.utils import generate_match_all_bytecodefrom products.error_tracking.backend.models import ErrorTrackingAssignmentRuleVALID_FILTERS = {@@ -233,6 +234,61 @@ class TestAssignmentRuleAPI(APIBaseTest):assert rule.filters == new_filtersassert rule.user_id == self.user.id+ @parameterized.expand(+ [+ ("empty_values", {"type": "AND", "values": []}),+ ("empty_nested_filter", {"type": "AND", "values": [{"type": "empty"}]}),+ ("or_empty_nested_filter", {"type": "OR", "values": [{"type": "empty"}]}),+ (+ "deeply_nested_empty",+ {"type": "AND", "values": [{"type": "AND", "values": [{"type": "empty"}]}]},+ ),+ ]+ )+ def test_create_with_no_op_filters_emits_match_all_bytecode(+ self, _name: str, empty_filters: dict[str, Any]+ ) -> None:+ response = self.client.post(+ self._url(),+ data={"filters": empty_filters, "assignee": {"type": "user", "id": self.user.id}},+ format="json",+ )++ assert response.status_code == status.HTTP_201_CREATED++ rule = ErrorTrackingAssignmentRule.objects.get(id=response.json()["id"])+ assert rule.disabled_data is None+ assert rule.bytecode == generate_match_all_bytecode()++ @parameterized.expand(+ [+ ("empty_values", {"type": "AND", "values": []}),+ ("empty_nested_filter", {"type": "AND", "values": [{"type": "empty"}]}),+ ("or_empty_nested_filter", {"type": "OR", "values": [{"type": "empty"}]}),+ (+ "deeply_nested_empty",+ {"type": "AND", "values": [{"type": "AND", "values": [{"type": "empty"}]}]},+ ),+ ]+ )+ def test_update_with_no_op_filters_emits_match_all_bytecode(+ self, _name: str, empty_filters: dict[str, Any]+ ) -> None:+ rule = self._create_rule()++ response = self.client.patch(+ self._url(str(rule.id)),+ data={"filters": empty_filters},+ format="json",+ )++ assert response.status_code == status.HTTP_204_NO_CONTENT++ rule.refresh_from_db()+ assert rule.filters == empty_filters+ assert rule.disabled_data is None+ assert rule.bytecode == generate_match_all_bytecode()+def test_update_accepts_frontend_payload_shape_with_extra_fields(self) -> None:rule = self._create_rule()new_filters = {diff --git a/products/error_tracking/backend/api/test/test_grouping_rules.py b/products/error_tracking/backend/api/test/test_grouping_rules.pyindex b8adcbadaec4..cc5eb5f19cbe 100644--- a/products/error_tracking/backend/api/test/test_grouping_rules.py+++ b/products/error_tracking/backend/api/test/test_grouping_rules.py@@ -150,6 +150,30 @@ class TestGroupingRuleAPI(APIBaseTest):assert body["attr"] == "filters"assert body["detail"] == "Invalid filters payload."+ @parameterized.expand(+ [+ ("empty_values", {"type": "AND", "values": []}),+ ("empty_nested_filter", {"type": "AND", "values": [{"type": "empty"}]}),+ ("or_empty_nested_filter", {"type": "OR", "values": [{"type": "empty"}]}),+ (+ "deeply_nested_empty",+ {"type": "AND", "values": [{"type": "AND", "values": [{"type": "empty"}]}]},+ ),+ ]+ )+ def test_create_rejects_no_op_filters(self, _name: str, empty_filters: dict[str, Any]) -> None:+ response = self.client.post(+ self._url(),+ data={"filters": empty_filters},+ format="json",+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST+ body = response.json()+ assert body["type"] == "validation_error"+ assert body["attr"] == "filters"+ assert body["detail"] == "Filters must contain at least one filter value."+@parameterized.expand([("user_type_with_uuid_id", {"type": "user", "id": str(uuid4())}, "User assignee IDs must be integers."),diff --git a/products/error_tracking/backend/api/test/test_suppression_rules.py b/products/error_tracking/backend/api/test/test_suppression_rules.pyindex e28e27cf2038..7f65f2054a7d 100644--- a/products/error_tracking/backend/api/test/test_suppression_rules.py+++ b/products/error_tracking/backend/api/test/test_suppression_rules.py@@ -432,6 +432,19 @@ class TestSuppressionRuleAPI(APIBaseTest):assert response.json()["attr"] == "filters"assert response.json()["detail"] == "Invalid filters"+ def test_create_rejects_non_dict_filter_entries_with_400(self) -> None:+ response = self.client.post(+ self._url(),+ data={"filters": {"type": "AND", "values": [1]}},+ format="json",+ )++ assert response.status_code == status.HTTP_400_BAD_REQUEST+ body = response.json()+ assert body["type"] == "validation_error"+ assert body["attr"] == "filters"+ assert body["detail"] == "Invalid filters payload."+def test_create_rejects_invalid_filters_shape_without_leaking_exception(self) -> None:response = self.client.post(self._url(),diff --git a/products/error_tracking/backend/api/utils.py b/products/error_tracking/backend/api/utils.pyindex dc00614571f8..1fd5845caa59 100644--- a/products/error_tracking/backend/api/utils.py+++ b/products/error_tracking/backend/api/utils.py@@ -76,6 +76,23 @@ def generate_match_all_bytecode():return create_bytecode(with_return).bytecode+def has_filter_values(json_filters: dict) -> bool:+ """Check whether a filter dict contains any actual filter values, recursively.++ Non-dict entries are treated as "has values" so the request reaches pydantic+ validation and gets rejected with a 400 instead of raising AttributeError.+ """+ values = json_filters.get("values", [])+ if not values:+ return False+ for v in values:+ if not isinstance(v, dict):+ return True+ if "key" in v or has_filter_values(v):+ return True+ return False++def validate_bytecode(bytecode: list[Any]) -> None:for i, op in enumerate(bytecode):if not isinstance(op, Operation):