: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
refactor(devex): label dataclass enum fields in the schema, not the serializer (#114486)
Julian Bez5a8d7ac7d861
diff --git a/.agents/skills/improving-drf-endpoints/SKILL.md b/.agents/skills/improving-drf-endpoints/SKILL.mdindex abc02a64b2ec..8f680ac5d5e2 100644--- a/.agents/skills/improving-drf-endpoints/SKILL.md+++ b/.agents/skills/improving-drf-endpoints/SKILL.md@@ -127,8 +127,8 @@ this — just register under `routers.projects` and the middleware handles the aFor products using the facade pattern (e.g., `visual_review`) with `DataclassSerializer` wrapping frozen dataclasses from `contracts.py`:- Field types are auto-derived from the dataclass — fewer typing issues by design-- Subclass `LabeledChoicesDataclassSerializer` from `posthog/api/dataclass_serializers.py`, not the library `DataclassSerializer`.- The library labels enum choices with member names, so a `LabeledStrEnum` field gets no class-derived OpenAPI name and falls back to the field name.+- Type enum fields as `LabeledStrEnum`/`LabeledIntEnum` (or a Django `Choices` class), not a plain `StrEnum`.+ A schema extension in `posthog/api/documentation.py` documents those fields with their class labels, so their OpenAPI enum is named after the class. A plain `StrEnum` falls back to a field-derived name.- Focus on **`help_text`** (dataclass fields don't carry it; add it on the serializer field overrides)- **`@validated_request`** is already the standard pattern — verify response serializers are declared- `@extend_schema` tags and descriptions still need to be set on viewset methodsdiff --git a/posthog/api/dataclass_serializers.py b/posthog/api/dataclass_serializers.pydeleted file mode 100644index 5bccba37948f..000000000000--- a/posthog/api/dataclass_serializers.py+++ /dev/null@@ -1,24 +0,0 @@-from typing import TypeVar--from django.db.models import Choices--from rest_framework_dataclasses.field_utils import TypeInfo-from rest_framework_dataclasses.serializers import DataclassSerializer, SerializerFieldDefinition-from rest_framework_dataclasses.types import Dataclass--from posthog.enums import LabeledEnumType--T = TypeVar("T", bound=Dataclass)---# Enum fields carry the class labels, so posthog/openapi/enum_names.py names the OpenAPI enum after-# the class. The library pairs each value with the member name ("OPEN"), and no class carries that-# choice set. This is a comment and not a docstring because drf-spectacular copies a class docstring-# into the component description of every subclass.-class LabeledChoicesDataclassSerializer(DataclassSerializer[T]):- def build_enum_field(self, field_name: str, type_info: TypeInfo) -> SerializerFieldDefinition:- field_class, field_kwargs = super().build_enum_field(field_name, type_info)- enum_class = type_info.base_type- if isinstance(enum_class, LabeledEnumType) or issubclass(enum_class, Choices):- field_kwargs["choices"] = enum_class.choices- return field_class, field_kwargsdiff --git a/posthog/api/documentation.py b/posthog/api/documentation.pyindex 38c804f579bc..7928d02eb979 100644--- a/posthog/api/documentation.py+++ b/posthog/api/documentation.py@@ -1,10 +1,12 @@import osimport re+import copyfrom typing import Any, get_argsfrom django.core.exceptions import ImproperlyConfiguredfrom django.db import models+from drf_spectacular.contrib.rest_framework_dataclasses import OpenApiDataclassSerializerExtensionsfrom drf_spectacular.drainage import warn as spectacular_warnfrom drf_spectacular.extensions import OpenApiAuthenticationExtensionfrom drf_spectacular.openapi import AutoSchema@@ -19,7 +21,9 @@ from drf_spectacular.utils import () # # noqa: F401 for easy importfrom rest_framework import fields, serializersfrom rest_framework.exceptions import PermissionDenied+from rest_framework_dataclasses.fields import EnumField as DataclassEnumField+from posthog.enums import LabeledEnumTypefrom posthog.models.entity import MathTypefrom posthog.models.property import OperatorType, PropertyTypefrom posthog.permissions import APIScopePermission@@ -182,6 +186,37 @@ class ValueField(serializers.Field):return data+def _use_class_labels(field: serializers.Field) -> None:+ child = getattr(field, "child", None)+ if isinstance(child, serializers.Field):+ _use_class_labels(child)+ if not isinstance(field, DataclassEnumField) or field.by_name:+ return+ enum_class = field.enum_class+ if not (isinstance(enum_class, LabeledEnumType) or issubclass(enum_class, models.Choices)):+ return+ # Leave choices that a declared field or extra_kwargs set on purpose.+ library_default = {field.to_representation(member): member.name for member in enum_class}+ if dict(field.choices) == library_default:+ field.choices = enum_class.choices+++# rest_framework_dataclasses labels enum choices with member names, which no class carries, so+# posthog/openapi/enum_names.py cannot name those enums after their class. This fixes the schema only.+class LabeledEnumDataclassSerializerExtension(OpenApiDataclassSerializerExtensions):+ priority = 1++ def map_serializer(self, auto_schema: AutoSchema, direction: Any) -> dict[str, Any]:+ # drf-spectacular reuses instances passed to extend_schema, so map a copy. A shallow copy keeps+ # partial=True on PATCH bodies, and dropping the cached fields gives the copy fresh ones.+ serializer = copy.copy(self.target)+ serializer.__dict__.pop("fields", None)+ for field in serializer.fields.values():+ _use_class_labels(field)+ schema = auto_schema._map_serializer(serializer, direction, bypass_extensions=True)+ return self.strip_library_doc(schema)++class PersonalAPIKeyScheme(OpenApiAuthenticationExtension):target_class = "posthog.auth.PersonalAPIKeyAuthentication"name = "PersonalAPIKeyAuth"diff --git a/posthog/api/test/test_documentation_enum_labels.py b/posthog/api/test/test_documentation_enum_labels.pynew file mode 100644index 000000000000..5dfaef9cbbee--- /dev/null+++ b/posthog/api/test/test_documentation_enum_labels.py@@ -0,0 +1,73 @@+from dataclasses import dataclass, field+from typing import Any, cast++from django.test import SimpleTestCase++from drf_spectacular.openapi import AutoSchema+from parameterized import parameterized+from rest_framework_dataclasses.serializers import DataclassSerializer++from posthog.api.documentation import LabeledEnumDataclassSerializerExtension, _use_class_labels+from posthog.enums import LabeledStrEnum+++class _Kind(LabeledStrEnum):+ OPEN = "open"+ CLOSED_NOW = "closed_now"+++@dataclass(frozen=True)+class _Row:+ kind: _Kind+ kinds: list[_Kind] = field(default_factory=list)+ by_name: _Kind = _Kind.OPEN+ custom: _Kind = _Kind.OPEN+++class _RowSerializer(DataclassSerializer):+ class Meta:+ dataclass = _Row+ extra_kwargs = {+ "by_name": {"by_name": True},+ "custom": {"choices": [("open", "Only open")]},+ }+++class _CapturingAutoSchema:+ def __init__(self) -> None:+ self.mapped: Any = None++ def _map_serializer(self, serializer: Any, *_args: Any, **_kwargs: Any) -> dict[str, Any]:+ self.mapped = serializer+ return {}+++def _choices(serializer_field: Any) -> dict[str, str]:+ return dict(getattr(serializer_field, "child", serializer_field).choices)+++class TestEnumLabelsExtension(SimpleTestCase):+ @parameterized.expand(+ [+ ("kind", {"open": "Open", "closed_now": "Closed Now"}),+ ("kinds", {"open": "Open", "closed_now": "Closed Now"}),+ ("by_name", {"OPEN": "OPEN", "CLOSED_NOW": "CLOSED_NOW"}),+ ("custom", {"open": "Only open"}),+ ]+ )+ def test_use_class_labels(self, field_name: str, expected: dict[str, str]) -> None:+ serializer_field = _RowSerializer().fields[field_name]+ _use_class_labels(serializer_field)+ assert _choices(serializer_field) == expected++ @parameterized.expand([(True,), (False,)])+ def test_extension_maps_a_copy_and_keeps_partial(self, partial: bool) -> None:+ original = _RowSerializer(partial=partial)+ auto_schema = _CapturingAutoSchema()++ LabeledEnumDataclassSerializerExtension(original).map_serializer(cast(AutoSchema, auto_schema), "response")++ assert auto_schema.mapped is not original+ assert auto_schema.mapped.partial is partial+ assert _choices(auto_schema.mapped.fields["kind"]) == {"open": "Open", "closed_now": "Closed Now"}+ assert _choices(original.fields["kind"]) == {"open": "OPEN", "closed_now": "CLOSED_NOW"}diff --git a/products/engineering_analytics/backend/presentation/serializers/_shared.py b/products/engineering_analytics/backend/presentation/serializers/_shared.pyindex 8ce22af395e9..b36aa2bd9245 100644--- a/products/engineering_analytics/backend/presentation/serializers/_shared.py+++ b/products/engineering_analytics/backend/presentation/serializers/_shared.py@@ -1,11 +1,11 @@"""Serializers shared across domain modules, and their own leaves."""-from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import CIFailureLogLine, CIJobFailureLog, RepoRef-class RepoRefSerializer(LabeledChoicesDataclassSerializer):+class RepoRefSerializer(DataclassSerializer):class Meta:dataclass = RepoRefextra_kwargs = {@@ -15,7 +15,7 @@ class RepoRefSerializer(LabeledChoicesDataclassSerializer):}-class CIFailureLogLineSerializer(LabeledChoicesDataclassSerializer):+class CIFailureLogLineSerializer(DataclassSerializer):class Meta:dataclass = CIFailureLogLineextra_kwargs = {@@ -28,7 +28,7 @@ class CIFailureLogLineSerializer(LabeledChoicesDataclassSerializer):}-class CIJobFailureLogSerializer(LabeledChoicesDataclassSerializer):+class CIJobFailureLogSerializer(DataclassSerializer):lines = CIFailureLogLineSerializer(many=True, help_text="The thinned failure-log lines in original order, with omission markers.")diff --git a/products/engineering_analytics/backend/presentation/serializers/ci_signals.py b/products/engineering_analytics/backend/presentation/serializers/ci_signals.pyindex dfb01aedcec1..4007c0ac5ea2 100644--- a/products/engineering_analytics/backend/presentation/serializers/ci_signals.py+++ b/products/engineering_analytics/backend/presentation/serializers/ci_signals.py@@ -1,13 +1,12 @@"""Payloads for the atomic CI Signals configuration endpoint."""from rest_framework import serializers--from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import CISignalsConfig-class CISignalsConfigSerializer(LabeledChoicesDataclassSerializer):+class CISignalsConfigSerializer(DataclassSerializer):class Meta:dataclass = CISignalsConfigextra_kwargs = {diff --git a/products/engineering_analytics/backend/presentation/serializers/delivery.py b/products/engineering_analytics/backend/presentation/serializers/delivery.pyindex eee94cc3f991..bb59dc41839b 100644--- a/products/engineering_analytics/backend/presentation/serializers/delivery.py+++ b/products/engineering_analytics/backend/presentation/serializers/delivery.py@@ -1,7 +1,7 @@"""Payloads for the delivery reads: a scope's delivery summary, its pull request timelines, and an author'scomparison with their team."""-from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import (DeliveryComparison,@@ -27,7 +27,7 @@ _SCOPE_KIND_HELP = ()-class ScopeRepoFigureSerializer(LabeledChoicesDataclassSerializer):+class ScopeRepoFigureSerializer(DataclassSerializer):class Meta:dataclass = ScopeRepoFigureextra_kwargs = {@@ -47,7 +47,7 @@ def _figure(help_text: str) -> ScopeRepoFigureSerializer:return ScopeRepoFigureSerializer(help_text=help_text)-class DurationDistributionSerializer(LabeledChoicesDataclassSerializer):+class DurationDistributionSerializer(DataclassSerializer):class Meta:dataclass = DurationDistributionextra_kwargs = {@@ -63,7 +63,7 @@ class DurationDistributionSerializer(LabeledChoicesDataclassSerializer):}-class ScopeRepoDistributionSerializer(LabeledChoicesDataclassSerializer):+class ScopeRepoDistributionSerializer(DataclassSerializer):scope = DurationDistributionSerializer(help_text="The deployed pull requests in scope.")repo = DurationDistributionSerializer(help_text="Every deployed pull request in the repository.")@@ -71,7 +71,7 @@ class ScopeRepoDistributionSerializer(LabeledChoicesDataclassSerializer):dataclass = ScopeRepoDistribution-class DeliveryLeadTimeSerializer(LabeledChoicesDataclassSerializer):+class DeliveryLeadTimeSerializer(DataclassSerializer):open_to_deploy = ScopeRepoDistributionSerializer(help_text="Open to the first successful deploy containing the merge, over PRs deployed in the window.")@@ -99,7 +99,7 @@ class DeliveryLeadTimeSerializer(LabeledChoicesDataclassSerializer):}-class DeliverySummarySerializer(LabeledChoicesDataclassSerializer):+class DeliverySummarySerializer(DataclassSerializer):cost_per_merged_pr_usd = _figure("Median estimated CI cost per merged PR, in USD, over every run linked to the PR (merge-queue gate runs ""included) that started up to 30 days before the window. Null when the jobs table isn't synced."@@ -176,7 +176,7 @@ class DeliverySummarySerializer(LabeledChoicesDataclassSerializer):}-class PRTimelineSegmentSerializer(LabeledChoicesDataclassSerializer):+class PRTimelineSegmentSerializer(DataclassSerializer):class Meta:dataclass = PRTimelineSegmentextra_kwargs = {@@ -194,7 +194,7 @@ class PRTimelineSegmentSerializer(LabeledChoicesDataclassSerializer):}-class PRTimelinePushSerializer(LabeledChoicesDataclassSerializer):+class PRTimelinePushSerializer(DataclassSerializer):class Meta:dataclass = PRTimelinePushextra_kwargs = {@@ -205,7 +205,7 @@ class PRTimelinePushSerializer(LabeledChoicesDataclassSerializer):}-class PRTimelineRedTimeSerializer(LabeledChoicesDataclassSerializer):+class PRTimelineRedTimeSerializer(DataclassSerializer):class Meta:dataclass = PRTimelineRedTimeextra_kwargs = {@@ -214,7 +214,7 @@ class PRTimelineRedTimeSerializer(LabeledChoicesDataclassSerializer):}-class PRTimelineSerializer(LabeledChoicesDataclassSerializer):+class PRTimelineSerializer(DataclassSerializer):repo = RepoRefSerializer(help_text="The repository the pull request belongs to.")pushes = PRTimelinePushSerializer(many=True,@@ -252,7 +252,7 @@ class PRTimelineSerializer(LabeledChoicesDataclassSerializer):}-class PullRequestTimelinesSerializer(LabeledChoicesDataclassSerializer):+class PullRequestTimelinesSerializer(DataclassSerializer):items = PRTimelineSerializer(many=True,help_text="The pull requests in scope, newest first: open PRs plus PRs merged in the window, or the one "@@ -289,7 +289,7 @@ class PullRequestTimelinesSerializer(LabeledChoicesDataclassSerializer):}-class ReadyToMergeMediansSerializer(LabeledChoicesDataclassSerializer):+class ReadyToMergeMediansSerializer(DataclassSerializer):class Meta:dataclass = ReadyToMergeMediansextra_kwargs = {@@ -320,7 +320,7 @@ class ReadyToMergeMediansSerializer(LabeledChoicesDataclassSerializer):}-class PullRequestReadyToMergeSerializer(LabeledChoicesDataclassSerializer):+class PullRequestReadyToMergeSerializer(DataclassSerializer):class Meta:dataclass = PullRequestReadyToMergeextra_kwargs = {@@ -344,7 +344,7 @@ class PullRequestReadyToMergeSerializer(LabeledChoicesDataclassSerializer):}-class TeamReadyToMergeMediansSerializer(LabeledChoicesDataclassSerializer):+class TeamReadyToMergeMediansSerializer(DataclassSerializer):medians = ReadyToMergeMediansSerializer(allow_null=True,help_text="Over the pull requests by the team's members, the same population as a github_team scope, "@@ -358,7 +358,7 @@ class TeamReadyToMergeMediansSerializer(LabeledChoicesDataclassSerializer):extra_kwargs = {"github_team": {"help_text": "The GitHub team slug."}}-class DeliveryComparisonSerializer(LabeledChoicesDataclassSerializer):+class DeliveryComparisonSerializer(DataclassSerializer):author_medians = ReadyToMergeMediansSerializer(help_text="Over the author's pull requests, without the pr_number pull request.")diff --git a/products/engineering_analytics/backend/presentation/serializers/dora.py b/products/engineering_analytics/backend/presentation/serializers/dora.pyindex 37d65a62d154..db796f6e6fb3 100644--- a/products/engineering_analytics/backend/presentation/serializers/dora.py+++ b/products/engineering_analytics/backend/presentation/serializers/dora.py@@ -1,8 +1,7 @@"""Payloads for the DORA deploy-metrics read."""from rest_framework import serializers--from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import (DeploymentFrequencyBucket,@@ -21,7 +20,7 @@ class DoraEnvironmentQuerySerializer(serializers.Serializer):)-class DeploymentFrequencyBucketSerializer(LabeledChoicesDataclassSerializer):+class DeploymentFrequencyBucketSerializer(DataclassSerializer):class Meta:dataclass = DeploymentFrequencyBucketextra_kwargs = {@@ -35,7 +34,7 @@ class DeploymentFrequencyBucketSerializer(LabeledChoicesDataclassSerializer):}-class LeadTimeBucketSerializer(LabeledChoicesDataclassSerializer):+class LeadTimeBucketSerializer(DataclassSerializer):class Meta:dataclass = LeadTimeBucketextra_kwargs = {@@ -85,7 +84,7 @@ class LeadTimeBucketSerializer(LabeledChoicesDataclassSerializer):}-class DoraOverviewSerializer(LabeledChoicesDataclassSerializer):+class DoraOverviewSerializer(DataclassSerializer):deployment_frequency_series = DeploymentFrequencyBucketSerializer(many=True,help_text="Successful deployments per bucket across the window, oldest first, zero-filled, "diff --git a/products/engineering_analytics/backend/presentation/serializers/friction.py b/products/engineering_analytics/backend/presentation/serializers/friction.pyindex 70e3ea00c23d..42d6fb86fe7a 100644--- a/products/engineering_analytics/backend/presentation/serializers/friction.py+++ b/products/engineering_analytics/backend/presentation/serializers/friction.py@@ -1,6 +1,6 @@"""Payloads for the friction read: every author's friction as a multiple of the typical author."""-from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import (AuthorFriction,@@ -14,7 +14,7 @@ from products.engineering_analytics.backend.facade.contracts import ()-class FrictionGroupShareSerializer(LabeledChoicesDataclassSerializer):+class FrictionGroupShareSerializer(DataclassSerializer):class Meta:dataclass = FrictionGroupShareextra_kwargs = {@@ -26,7 +26,7 @@ class FrictionGroupShareSerializer(LabeledChoicesDataclassSerializer):}-class AuthorFrictionSerializer(LabeledChoicesDataclassSerializer):+class AuthorFrictionSerializer(DataclassSerializer):groups = FrictionGroupShareSerializer(many=True, help_text="The score split by the kind of friction.")class Meta:@@ -52,7 +52,7 @@ class AuthorFrictionSerializer(LabeledChoicesDataclassSerializer):}-class TeamFrictionSerializer(LabeledChoicesDataclassSerializer):+class TeamFrictionSerializer(DataclassSerializer):class Meta:dataclass = TeamFrictionextra_kwargs = {@@ -65,7 +65,7 @@ class TeamFrictionSerializer(LabeledChoicesDataclassSerializer):}-class PullRequestFrictionItemSerializer(LabeledChoicesDataclassSerializer):+class PullRequestFrictionItemSerializer(DataclassSerializer):groups = FrictionGroupShareSerializer(many=True, help_text="The pull request's friction split by kind.")class Meta:@@ -79,7 +79,7 @@ class PullRequestFrictionItemSerializer(LabeledChoicesDataclassSerializer):}-class AuthorFrictionListSerializer(LabeledChoicesDataclassSerializer):+class AuthorFrictionListSerializer(DataclassSerializer):items = AuthorFrictionSerializer(many=True, help_text="Authors by friction, most first.")teams = TeamFrictionSerializer(many=True, help_text="Teams with at least 3 scored members, by median member friction, most first."@@ -104,7 +104,7 @@ class AuthorFrictionListSerializer(LabeledChoicesDataclassSerializer):}-class AuthorFrictionDetailSerializer(LabeledChoicesDataclassSerializer):+class AuthorFrictionDetailSerializer(DataclassSerializer):author = AuthorFrictionSerializer(allow_null=True, help_text="The author's score and rank. Null below 3 merged pull requests in the window.")@@ -130,7 +130,7 @@ class AuthorFrictionDetailSerializer(LabeledChoicesDataclassSerializer):}-class PullRequestFrictionBreakdownSerializer(LabeledChoicesDataclassSerializer):+class PullRequestFrictionBreakdownSerializer(DataclassSerializer):groups = FrictionGroupShareSerializer(many=True, help_text="The pull request's friction split by kind.")class Meta:@@ -155,7 +155,7 @@ class PullRequestFrictionBreakdownSerializer(LabeledChoicesDataclassSerializer):}-class PullRequestFrictionDetailSerializer(LabeledChoicesDataclassSerializer):+class PullRequestFrictionDetailSerializer(DataclassSerializer):pull_request = PullRequestFrictionBreakdownSerializer(allow_null=True,help_text="Null when the pull request did not merge in the window, or a bot authored it.",diff --git a/products/engineering_analytics/backend/presentation/serializers/pull_requests.py b/products/engineering_analytics/backend/presentation/serializers/pull_requests.pyindex 6974dc635786..e7d37614a11c 100644--- a/products/engineering_analytics/backend/presentation/serializers/pull_requests.py+++ b/products/engineering_analytics/backend/presentation/serializers/pull_requests.py@@ -1,6 +1,6 @@"""Payloads for PR-scoped reads: backlog cards, lists, lifecycle, logs, and cost."""-from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import (AttentionPullRequestList,@@ -26,7 +26,7 @@ from products.engineering_analytics.backend.presentation.serializers._shared imp)-class AuthorSerializer(LabeledChoicesDataclassSerializer):+class AuthorSerializer(DataclassSerializer):class Meta:dataclass = Authorextra_kwargs = {@@ -37,7 +37,7 @@ class AuthorSerializer(LabeledChoicesDataclassSerializer):}-class PullRequestSerializer(LabeledChoicesDataclassSerializer):+class PullRequestSerializer(DataclassSerializer):author = AuthorSerializer(help_text="The pull request author.")repo = RepoRefSerializer(help_text="Repository the pull request belongs to.")@@ -55,7 +55,7 @@ class PullRequestSerializer(LabeledChoicesDataclassSerializer):}-class PRLifecycleEventSerializer(LabeledChoicesDataclassSerializer):+class PRLifecycleEventSerializer(DataclassSerializer):class Meta:dataclass = PRLifecycleEventextra_kwargs = {@@ -77,7 +77,7 @@ class PRLifecycleEventSerializer(LabeledChoicesDataclassSerializer):}-class PRLifecycleSerializer(LabeledChoicesDataclassSerializer):+class PRLifecycleSerializer(DataclassSerializer):pull_request = PullRequestSerializer(help_text="The pull request header.")events = PRLifecycleEventSerializer(many=True, help_text="Lifecycle events ordered by time.")@@ -90,7 +90,7 @@ class PRLifecycleSerializer(LabeledChoicesDataclassSerializer):}-class CIFailureLogsSerializer(LabeledChoicesDataclassSerializer):+class CIFailureLogsSerializer(DataclassSerializer):repo = RepoRefSerializer(help_text="Repository the pull request belongs to.")jobs = CIJobFailureLogSerializer(many=True, help_text="Failed CI jobs with their thinned failure logs, grouped by job."@@ -111,7 +111,7 @@ class CIFailureLogsSerializer(LabeledChoicesDataclassSerializer):}-class WorkflowCostSerializer(LabeledChoicesDataclassSerializer):+class WorkflowCostSerializer(DataclassSerializer):class Meta:dataclass = WorkflowCostextra_kwargs = {@@ -127,7 +127,7 @@ class WorkflowCostSerializer(LabeledChoicesDataclassSerializer):}-class RunCostSerializer(LabeledChoicesDataclassSerializer):+class RunCostSerializer(DataclassSerializer):class Meta:dataclass = RunCostextra_kwargs = {@@ -142,7 +142,7 @@ class RunCostSerializer(LabeledChoicesDataclassSerializer):}-class PRLLMSpendSerializer(LabeledChoicesDataclassSerializer):+class PRLLMSpendSerializer(DataclassSerializer):class Meta:dataclass = PRLLMSpendextra_kwargs = {@@ -158,7 +158,7 @@ class PRLLMSpendSerializer(LabeledChoicesDataclassSerializer):}-class PRCostSummarySerializer(LabeledChoicesDataclassSerializer):+class PRCostSummarySerializer(DataclassSerializer):by_workflow = WorkflowCostSerializer(many=True, help_text="Same spend broken down per workflow.")by_run = RunCostSerializer(many=True, help_text="Same spend broken down per workflow run, keyed by (run_id, run_attempt)."@@ -197,7 +197,7 @@ class PRCostSummarySerializer(LabeledChoicesDataclassSerializer):}-class CIStatusRollupSerializer(LabeledChoicesDataclassSerializer):+class CIStatusRollupSerializer(DataclassSerializer):class Meta:dataclass = CIStatusRollupextra_kwargs = {@@ -217,7 +217,7 @@ class CIStatusRollupSerializer(LabeledChoicesDataclassSerializer):}-class PushCISampleSerializer(LabeledChoicesDataclassSerializer):+class PushCISampleSerializer(DataclassSerializer):class Meta:dataclass = PushCISampleextra_kwargs = {@@ -235,7 +235,7 @@ class PushCISampleSerializer(LabeledChoicesDataclassSerializer):}-class PullRequestListItemSerializer(LabeledChoicesDataclassSerializer):+class PullRequestListItemSerializer(DataclassSerializer):author = AuthorSerializer(help_text="The pull request author.")repo = RepoRefSerializer(help_text="Repository the pull request belongs to.")ci = CIStatusRollupSerializer(help_text="CI status from the latest workflow runs on the head SHA.")@@ -287,7 +287,7 @@ class PullRequestListItemSerializer(LabeledChoicesDataclassSerializer):}-class PullRequestListSerializer(LabeledChoicesDataclassSerializer):+class PullRequestListSerializer(DataclassSerializer):items = PullRequestListItemSerializer(many=True, help_text="This page of pull requests, newest first, capped at `limit`.")@@ -303,7 +303,7 @@ class PullRequestListSerializer(LabeledChoicesDataclassSerializer):}-class AttentionPullRequestListSerializer(LabeledChoicesDataclassSerializer):+class AttentionPullRequestListSerializer(DataclassSerializer):items = PullRequestListItemSerializer(many=True, help_text="Open pull requests needing attention, failing CI first, then newest, capped at `limit`.")@@ -318,7 +318,7 @@ class AttentionPullRequestListSerializer(LabeledChoicesDataclassSerializer):}-class BranchPRMatchSerializer(LabeledChoicesDataclassSerializer):+class BranchPRMatchSerializer(DataclassSerializer):class Meta:dataclass = BranchPRMatchextra_kwargs = {@@ -335,7 +335,7 @@ class BranchPRMatchSerializer(LabeledChoicesDataclassSerializer):}-class CICardSummarySerializer(LabeledChoicesDataclassSerializer):+class CICardSummarySerializer(DataclassSerializer):class Meta:dataclass = CICardSummaryextra_kwargs = {diff --git a/products/engineering_analytics/backend/presentation/serializers/sources.py b/products/engineering_analytics/backend/presentation/serializers/sources.pyindex 753364685d2c..785a19ff4ba1 100644--- a/products/engineering_analytics/backend/presentation/serializers/sources.py+++ b/products/engineering_analytics/backend/presentation/serializers/sources.py@@ -1,11 +1,11 @@"""Payload for the GitHub source/repo picker."""-from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import GitHubSource-class GitHubSourceSerializer(LabeledChoicesDataclassSerializer):+class GitHubSourceSerializer(DataclassSerializer):class Meta:dataclass = GitHubSourceextra_kwargs = {diff --git a/products/engineering_analytics/backend/presentation/serializers/suite_health.py b/products/engineering_analytics/backend/presentation/serializers/suite_health.pyindex ef4725c94c1b..82ff0c1ec8bd 100644--- a/products/engineering_analytics/backend/presentation/serializers/suite_health.py+++ b/products/engineering_analytics/backend/presentation/serializers/suite_health.py@@ -1,6 +1,6 @@"""Payloads for test-health reads and the quarantine sidecar."""-from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import (BrokenTestRow,@@ -18,7 +18,7 @@ from products.engineering_analytics.backend.facade.contracts import (from products.engineering_analytics.backend.presentation.serializers._shared import RepoRefSerializer-class FlakyTestItemSerializer(LabeledChoicesDataclassSerializer):+class FlakyTestItemSerializer(DataclassSerializer):class Meta:dataclass = FlakyTestItemextra_kwargs = {@@ -65,7 +65,7 @@ class FlakyTestItemSerializer(LabeledChoicesDataclassSerializer):}-class TrunkQuarantinedTestSerializer(LabeledChoicesDataclassSerializer):+class TrunkQuarantinedTestSerializer(DataclassSerializer):class Meta:dataclass = TrunkQuarantinedTestextra_kwargs = {@@ -95,7 +95,7 @@ class TrunkQuarantinedTestSerializer(LabeledChoicesDataclassSerializer):}-class TrunkQuarantineTeamDebtSerializer(LabeledChoicesDataclassSerializer):+class TrunkQuarantineTeamDebtSerializer(DataclassSerializer):class Meta:dataclass = TrunkQuarantineTeamDebtextra_kwargs = {@@ -106,7 +106,7 @@ class TrunkQuarantineTeamDebtSerializer(LabeledChoicesDataclassSerializer):}-class TrunkQuarantineDebtSerializer(LabeledChoicesDataclassSerializer):+class TrunkQuarantineDebtSerializer(DataclassSerializer):teams = TrunkQuarantineTeamDebtSerializer(many=True,help_text="Per-team rollup, most indebted first: overdue count, then test count, then oldest age.",@@ -142,7 +142,7 @@ class TrunkQuarantineDebtSerializer(LabeledChoicesDataclassSerializer):}-class FlakyTestListSerializer(LabeledChoicesDataclassSerializer):+class FlakyTestListSerializer(DataclassSerializer):items = FlakyTestItemSerializer(many=True,help_text="Tests worth acting on now, ranked by blast radius: master failures, then PRs hit, then runs. "@@ -161,7 +161,7 @@ class FlakyTestListSerializer(LabeledChoicesDataclassSerializer):}-class BrokenTestRowSerializer(LabeledChoicesDataclassSerializer):+class BrokenTestRowSerializer(DataclassSerializer):class Meta:dataclass = BrokenTestRowextra_kwargs = {@@ -210,7 +210,7 @@ class BrokenTestRowSerializer(LabeledChoicesDataclassSerializer):}-class BrokenTestsResultSerializer(LabeledChoicesDataclassSerializer):+class BrokenTestsResultSerializer(DataclassSerializer):rows = BrokenTestRowSerializer(many=True,help_text="Classified failures ranked by triage urgency: breaking trunk first, single-PR failures last.",@@ -231,7 +231,7 @@ class BrokenTestsResultSerializer(LabeledChoicesDataclassSerializer):}-class QuarantineEntrySerializer(LabeledChoicesDataclassSerializer):+class QuarantineEntrySerializer(DataclassSerializer):class Meta:dataclass = QuarantineEntryextra_kwargs = {@@ -259,7 +259,7 @@ class QuarantineEntrySerializer(LabeledChoicesDataclassSerializer):}-class QuarantineFileSerializer(LabeledChoicesDataclassSerializer):+class QuarantineFileSerializer(DataclassSerializer):entries = QuarantineEntrySerializer(many=True,help_text="Quarantined selectors, most urgent first (overdue, in_grace, expiring_soon, active), "@@ -289,7 +289,7 @@ class QuarantineFileSerializer(LabeledChoicesDataclassSerializer):}-class QuarantineRequestSerializer(LabeledChoicesDataclassSerializer):+class QuarantineRequestSerializer(DataclassSerializer):class Meta:dataclass = QuarantineRequestextra_kwargs = {@@ -347,7 +347,7 @@ class QuarantineRequestSerializer(LabeledChoicesDataclassSerializer):}-class QuarantineRequestResultSerializer(LabeledChoicesDataclassSerializer):+class QuarantineRequestResultSerializer(DataclassSerializer):class Meta:dataclass = QuarantineRequestResultextra_kwargs = {diff --git a/products/engineering_analytics/backend/presentation/serializers/teams.py b/products/engineering_analytics/backend/presentation/serializers/teams.pyindex 33629dc63798..aab8b54f7aa1 100644--- a/products/engineering_analytics/backend/presentation/serializers/teams.py+++ b/products/engineering_analytics/backend/presentation/serializers/teams.py@@ -1,6 +1,6 @@"""Payloads for team-level rollups: CI health, activity, and merge trend."""-from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import (TeamCIActivity,@@ -12,7 +12,7 @@ from products.engineering_analytics.backend.facade.contracts import ()-class TeamCIHealthItemSerializer(LabeledChoicesDataclassSerializer):+class TeamCIHealthItemSerializer(DataclassSerializer):class Meta:dataclass = TeamCIHealthItemextra_kwargs = {@@ -68,7 +68,7 @@ class TeamCIHealthItemSerializer(LabeledChoicesDataclassSerializer):}-class TeamCIHealthListSerializer(LabeledChoicesDataclassSerializer):+class TeamCIHealthListSerializer(DataclassSerializer):items = TeamCIHealthItemSerializer(many=True,help_text="Owning teams ranked by current flaky + failure signal, heaviest first, capped at `limit`. "@@ -86,7 +86,7 @@ class TeamCIHealthListSerializer(LabeledChoicesDataclassSerializer):}-class TeamTestSignalSerializer(LabeledChoicesDataclassSerializer):+class TeamTestSignalSerializer(DataclassSerializer):class Meta:dataclass = TeamTestSignalextra_kwargs = {@@ -104,7 +104,7 @@ class TeamTestSignalSerializer(LabeledChoicesDataclassSerializer):}-class TeamCIActivitySerializer(LabeledChoicesDataclassSerializer):+class TeamCIActivitySerializer(DataclassSerializer):tests = TeamTestSignalSerializer(many=True,help_text="The team's owned tests with signal in either window, ranked by the stronger window's count "@@ -119,7 +119,7 @@ class TeamCIActivitySerializer(LabeledChoicesDataclassSerializer):}-class TeamMergeTrendPointSerializer(LabeledChoicesDataclassSerializer):+class TeamMergeTrendPointSerializer(DataclassSerializer):class Meta:dataclass = TeamMergeTrendPointextra_kwargs = {@@ -136,7 +136,7 @@ class TeamMergeTrendPointSerializer(LabeledChoicesDataclassSerializer):}-class TeamMergeTrendSerializer(LabeledChoicesDataclassSerializer):+class TeamMergeTrendSerializer(DataclassSerializer):points = TeamMergeTrendPointSerializer(many=True,help_text="Daily median and average open→merge over the PRs this team's members merged, ascending "diff --git a/products/engineering_analytics/backend/presentation/serializers/workflows.py b/products/engineering_analytics/backend/presentation/serializers/workflows.pyindex 56db700dfcba..75c1d317b14b 100644--- a/products/engineering_analytics/backend/presentation/serializers/workflows.py+++ b/products/engineering_analytics/backend/presentation/serializers/workflows.py@@ -1,6 +1,6 @@"""Payloads for workflow/run/job-scoped reads: health, activity, jobs, costs, and master state."""-from posthog.api.dataclass_serializers import LabeledChoicesDataclassSerializer+from rest_framework_dataclasses.serializers import DataclassSerializerfrom products.engineering_analytics.backend.facade.contracts import (CostPerMergeBucket,@@ -29,7 +29,7 @@ from products.engineering_analytics.backend.presentation.serializers._shared imp)-class WorkflowRunDetailSerializer(LabeledChoicesDataclassSerializer):+class WorkflowRunDetailSerializer(DataclassSerializer):repo = RepoRefSerializer(help_text="Repository the run belongs to.")class Meta:@@ -79,7 +79,7 @@ class WorkflowRunDetailSerializer(LabeledChoicesDataclassSerializer):}-class WorkflowRunActivityPointSerializer(LabeledChoicesDataclassSerializer):+class WorkflowRunActivityPointSerializer(DataclassSerializer):class Meta:dataclass = WorkflowRunActivityPointextra_kwargs = {@@ -104,7 +104,7 @@ class WorkflowRunActivityPointSerializer(LabeledChoicesDataclassSerializer):}-class WorkflowRunActivitySerializer(LabeledChoicesDataclassSerializer):+class WorkflowRunActivitySerializer(DataclassSerializer):points = WorkflowRunActivityPointSerializer(many=True, help_text="Per-run chart points, newest first, capped at `limit`.")@@ -120,7 +120,7 @@ class WorkflowRunActivitySerializer(LabeledChoicesDataclassSerializer):}-class WorkflowJobSerializer(LabeledChoicesDataclassSerializer):+class WorkflowJobSerializer(DataclassSerializer):class Meta:dataclass = WorkflowJobextra_kwargs = {@@ -158,7 +158,7 @@ class WorkflowJobSerializer(LabeledChoicesDataclassSerializer):}-class WorkflowRunnerCostSerializer(LabeledChoicesDataclassSerializer):+class WorkflowRunnerCostSerializer(DataclassSerializer):class Meta:dataclass = WorkflowRunnerCostextra_kwargs = {@@ -173,7 +173,7 @@ class WorkflowRunnerCostSerializer(LabeledChoicesDataclassSerializer):}-class WorkflowHealthBucketSerializer(LabeledChoicesDataclassSerializer):+class WorkflowHealthBucketSerializer(DataclassSerializer):class Meta:dataclass = WorkflowHealthBucketextra_kwargs = {@@ -190,7 +190,7 @@ class WorkflowHealthBucketSerializer(LabeledChoicesDataclassSerializer):}-class WorkflowHealthItemSerializer(LabeledChoicesDataclassSerializer):+class WorkflowHealthItemSerializer(DataclassSerializer):repo = RepoRefSerializer(help_text="Repository the workflow runs in.")buckets = WorkflowHealthBucketSerializer(many=True, help_text="Run history across the whole window, oldest first, zero-filled, bucketed by granularity."@@ -274,7 +274,7 @@ class WorkflowHealthItemSerializer(LabeledChoicesDataclassSerializer):}-class CostPerMergeBucketSerializer(LabeledChoicesDataclassSerializer):+class CostPerMergeBucketSerializer(DataclassSerializer):class Meta:dataclass = CostPerMergeBucketextra_kwargs = {@@ -296,7 +296,7 @@ class CostPerMergeBucketSerializer(LabeledChoicesDataclassSerializer):}-class TimeToGreenBucketSerializer(LabeledChoicesDataclassSerializer):+class TimeToGreenBucketSerializer(DataclassSerializer):class Meta:dataclass = TimeToGreenBucketextra_kwargs = {@@ -313,7 +313,7 @@ class TimeToGreenBucketSerializer(LabeledChoicesDataclassSerializer):}-class PassRateBucketSerializer(LabeledChoicesDataclassSerializer):+class PassRateBucketSerializer(DataclassSerializer):class Meta:dataclass = PassRateBucketextra_kwargs = {@@ -329,7 +329,7 @@ class PassRateBucketSerializer(LabeledChoicesDataclassSerializer):}-class OpenToMergeBucketSerializer(LabeledChoicesDataclassSerializer):+class OpenToMergeBucketSerializer(DataclassSerializer):class Meta:dataclass = OpenToMergeBucketextra_kwargs = {@@ -344,7 +344,7 @@ class OpenToMergeBucketSerializer(LabeledChoicesDataclassSerializer):}-class ReadyToMergeBucketSerializer(LabeledChoicesDataclassSerializer):+class ReadyToMergeBucketSerializer(DataclassSerializer):class Meta:dataclass = ReadyToMergeBucketextra_kwargs = {@@ -360,7 +360,7 @@ class ReadyToMergeBucketSerializer(LabeledChoicesDataclassSerializer):}-class DeliveryStageTimingSerializer(LabeledChoicesDataclassSerializer):+class DeliveryStageTimingSerializer(DataclassSerializer):class Meta:dataclass = DeliveryStageTimingextra_kwargs = {@@ -386,7 +386,7 @@ class DeliveryStageTimingSerializer(LabeledChoicesDataclassSerializer):}-class DeliveryPipelineSerializer(LabeledChoicesDataclassSerializer):+class DeliveryPipelineSerializer(DataclassSerializer):stages = DeliveryStageTimingSerializer(many=True,help_text="The legs, ordered open to merge. A leg with nothing observed still appears, "@@ -404,7 +404,7 @@ class DeliveryPipelineSerializer(LabeledChoicesDataclassSerializer):}-class RepoOverviewSerializer(LabeledChoicesDataclassSerializer):+class RepoOverviewSerializer(DataclassSerializer):cost_series = CostPerMergeBucketSerializer(many=True,help_text="CI cost per merged PR across the window, oldest first, zero-filled, bucketed by "@@ -646,7 +646,7 @@ class RepoOverviewSerializer(LabeledChoicesDataclassSerializer):}-class CurrentBranchHealthSerializer(LabeledChoicesDataclassSerializer):+class CurrentBranchHealthSerializer(DataclassSerializer):class Meta:dataclass = CurrentBranchHealthextra_kwargs = {@@ -664,7 +664,7 @@ class CurrentBranchHealthSerializer(LabeledChoicesDataclassSerializer):}-class MasterFailureGroupSerializer(LabeledChoicesDataclassSerializer):+class MasterFailureGroupSerializer(DataclassSerializer):repo = RepoRefSerializer(help_text="Repository the failures occurred in.")class Meta:@@ -684,7 +684,7 @@ class MasterFailureGroupSerializer(LabeledChoicesDataclassSerializer):}-class RunFailureLogsSerializer(LabeledChoicesDataclassSerializer):+class RunFailureLogsSerializer(DataclassSerializer):jobs = CIJobFailureLogSerializer(many=True, help_text="Failed CI jobs of this run with their thinned failure logs, grouped by job.")@@ -702,7 +702,7 @@ class RunFailureLogsSerializer(LabeledChoicesDataclassSerializer):}-class WorkflowJobAggregateSerializer(LabeledChoicesDataclassSerializer):+class WorkflowJobAggregateSerializer(DataclassSerializer):class Meta:dataclass = WorkflowJobAggregateextra_kwargs = {