: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
chore(devex): stop growing enums from generating no-op migrations (#86201)
Julian Bez2b9a307051a0
diff --git a/.agents/skills/django-migrations/SKILL.md b/.agents/skills/django-migrations/SKILL.mdindex 7a9f33e3a9bd..0ae53452ad12 100644--- a/.agents/skills/django-migrations/SKILL.md+++ b/.agents/skills/django-migrations/SKILL.md@@ -36,6 +36,30 @@ Delete an expired test instead of marking it skipped. Keep the migration file. FDo not apply this rule to migration tooling, migration safety checks, reusable backfill systems, or backfills that people can still run.+## Growing enums need callable choices++A `choices=` list that grows over time generates an `AlterField` on every addition, on every model that uses the enum. Those migrations emit **no SQL** — `choices` is in Django's `Field.non_db_attrs`, so the schema editor skips them — but they still land in migration state, in CI's per-shard migration replay, and in `max_migration.txt`, where they collide with every other migration waiting in the merge queue.++Pass a callable instead. Django resolves it lazily, so the migration records the function reference once and never changes again:++```python+def external_data_source_type_choices() -> list[tuple[str, str]]:+ return ExternalDataSourceType.choices+++source_type = models.CharField(max_length=128, choices=external_data_source_type_choices)+```++Runtime behavior is unchanged: DRF still builds a `ChoiceField`, so the OpenAPI enum and the generated frontend types are intact; `full_clean()` still rejects unknown values; admin still renders a dropdown; `get_FOO_display()` still resolves the label. A real schema change (`max_length`, `null`, a new field) still generates a migration.++Reach for a callable when the enum is a **registry** that grows as the org adds things — sources, integrations, products, providers, model ids. Keep a plain list for a **closed vocabulary** intrinsic to the domain, like a status or a priority, where a new member is a genuine domain change worth recording.++Two things a callable does not do for you:++- Migrations reference it by import path forever, so renaming or moving it needs its own migration. Keep it next to the enum it wraps.+- It has to be a module-level named function. A lambda or a closure returned by a shared factory has no importable path, so Django cannot serialize it — one small function per enum is the intended shape, not duplication to factor out.+- It hides choice growth from migration state, not from the column. A new member longer than the field's `max_length` is still a real schema change, so check the headroom when the registry grows.+## Workflow1. **Classify** the change as additive (new nullable column, new table) or risky (drop/rename, `NOT NULL`, indexes, constraints, large data updates, model moves). A change is also risky if it touches a [hot table](#hot-table-hazard), regardless of how additive it looks. See also the [cross-language `NOT NULL` hazard](#cross-language-not-null-hazard) below.diff --git a/posthog/migrations/1314_callable_choices.py b/posthog/migrations/1314_callable_choices.pynew file mode 100644index 000000000000..67fbe44a2f64--- /dev/null+++ b/posthog/migrations/1314_callable_choices.py@@ -0,0 +1,20 @@+# Generated by Django 5.2.17 on 2026-08-20 08:14++from django.db import migrations, models++import posthog.models.integration.model+++class Migration(migrations.Migration):+ dependencies = [("posthog", "1313_healthissue_snoozed_until")]++ operations = [+ migrations.AlterField(+ model_name="integration",+ name="kind",+ field=models.CharField(+ choices=posthog.models.integration.model.integration_kind_choices,+ max_length=32,+ ),+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex 2f52efab06a6..b5341a0a8773 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1313_healthissue_snoozed_until+1314_callable_choicesdiff --git a/posthog/models/integration/model.py b/posthog/models/integration/model.pyindex 978ed550893d..e115ad340eee 100644--- a/posthog/models/integration/model.py+++ b/posthog/models/integration/model.py@@ -4,6 +4,7 @@ from typing import Any, Self, castfrom django.db import modelsfrom django.db.models import Q+from django.utils.functional import Promiseimport structlogfrom prometheus_client import Counter@@ -118,6 +119,11 @@ class IntegrationManager(models.Manager["Integration"]):)+def integration_kind_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(Integration.IntegrationKind.choices)++class Integration(models.Model):class IntegrationKind(models.TextChoices):ANTHROPIC = "anthropic"@@ -173,7 +179,7 @@ class Integration(models.Model):team = models.ForeignKey("Team", on_delete=models.CASCADE)# The integration type identifier- kind = field_access_control(models.CharField(max_length=32, choices=IntegrationKind), "project", "admin")+ kind = field_access_control(models.CharField(max_length=32, choices=integration_kind_choices), "project", "admin")# The ID of the integration in the external systemintegration_id = field_access_control(models.TextField(null=True, blank=True), "project", "admin")# Any config that COULD be passed to the frontenddiff --git a/products/ai_observability/backend/migrations/0041_callable_choices.py b/products/ai_observability/backend/migrations/0041_callable_choices.pynew file mode 100644index 000000000000..5afe82d83630--- /dev/null+++ b/products/ai_observability/backend/migrations/0041_callable_choices.py@@ -0,0 +1,41 @@+# Generated by Django 5.2.17 on 2026-08-20 08:14++from django.db import migrations, models++import products.ai_observability.backend.models.evaluations+import products.ai_observability.backend.models.provider_keys+++class Migration(migrations.Migration):+ dependencies = [+ ("ai_observability", "0040_validate_dataset_item_version_ownership"),+ ]++ operations = [+ migrations.AlterField(+ model_name="evaluation",+ name="status_reason",+ field=models.CharField(+ blank=True,+ choices=products.ai_observability.backend.models.evaluations.evaluation_status_reason_choices,+ max_length=50,+ null=True,+ ),+ ),+ migrations.AlterField(+ model_name="llmmodelconfiguration",+ name="provider",+ field=models.CharField(+ choices=products.ai_observability.backend.models.provider_keys.llm_provider_choices,+ max_length=50,+ ),+ ),+ migrations.AlterField(+ model_name="llmproviderkey",+ name="provider",+ field=models.CharField(+ choices=products.ai_observability.backend.models.provider_keys.llm_provider_choices,+ max_length=50,+ ),+ ),+ ]diff --git a/products/ai_observability/backend/migrations/max_migration.txt b/products/ai_observability/backend/migrations/max_migration.txtindex 92687dd3e3cb..801d3b72f8cc 100644--- a/products/ai_observability/backend/migrations/max_migration.txt+++ b/products/ai_observability/backend/migrations/max_migration.txt@@ -1 +1 @@-0040_validate_dataset_item_version_ownership+0041_callable_choicesdiff --git a/products/ai_observability/backend/models/evaluations.py b/products/ai_observability/backend/models/evaluations.pyindex 3bc34ff8d9e9..501e29a1499f 100644--- a/products/ai_observability/backend/models/evaluations.py+++ b/products/ai_observability/backend/models/evaluations.py@@ -1,6 +1,7 @@from django.db import models, transactionfrom django.db.models.signals import post_savefrom django.dispatch import receiver+from django.utils.functional import Promiseimport structlog@@ -42,6 +43,11 @@ class EvaluationStatusReason(models.TextChoices):HOG_ERROR = "hog_error", "Hog evaluation code failed"+def evaluation_status_reason_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(EvaluationStatusReason.choices)++class EvaluationQuerySet(models.QuerySet):def using_provider_keys(self) -> "EvaluationQuerySet":return self.filter(evaluation_type=EvaluationType.LLM_JUDGE)@@ -94,7 +100,7 @@ class Evaluation(ModelActivityMixin, UUIDTModel):# backwards compatibility with existing API / DB callers. When status is ERROR, status_reason must be set.enabled = models.BooleanField(default=False)status = models.CharField(max_length=20, choices=EvaluationStatus, default=EvaluationStatus.PAUSED)- status_reason = models.CharField(max_length=50, choices=EvaluationStatusReason, null=True, blank=True)+ status_reason = models.CharField(max_length=50, choices=evaluation_status_reason_choices, null=True, blank=True)status_reason_detail = models.TextField(null=True, blank=True)evaluation_type = models.CharField(max_length=50, choices=EvaluationType)diff --git a/products/ai_observability/backend/models/model_configuration.py b/products/ai_observability/backend/models/model_configuration.pyindex 1734d710bc08..55b1a2aaaa50 100644--- a/products/ai_observability/backend/models/model_configuration.py+++ b/products/ai_observability/backend/models/model_configuration.py@@ -3,14 +3,14 @@ from django.db import modelsfrom posthog.models.utils import UUIDTModel-from .provider_keys import LLMProvider+from .provider_keys import llm_provider_choicesclass LLMModelConfiguration(UUIDTModel):"""Configuration for LLM model selection, used by evals and other features."""team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE)- provider = models.CharField(max_length=50, choices=LLMProvider)+ provider = models.CharField(max_length=50, choices=llm_provider_choices)model = models.CharField(max_length=100)provider_key = models.ForeignKey("ai_observability.LLMProviderKey",diff --git a/products/ai_observability/backend/models/provider_keys.py b/products/ai_observability/backend/models/provider_keys.pyindex c0dbe5f91473..3fbc337daa74 100644--- a/products/ai_observability/backend/models/provider_keys.py+++ b/products/ai_observability/backend/models/provider_keys.py@@ -3,6 +3,7 @@ from typing import Anyfrom django.db import models, transactionfrom django.db.models.signals import post_delete, post_savefrom django.dispatch import receiver+from django.utils.functional import Promisefrom posthog.helpers.encrypted_fields import EncryptedJSONFieldfrom posthog.models.utils import UUIDTModel@@ -23,6 +24,11 @@ class LLMProvider(models.TextChoices):ZEABUR = "zeabur", "Zeabur AI Hub"+def llm_provider_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(LLMProvider.choices)++class LLMProviderKey(UUIDTModel):class State(models.TextChoices):UNKNOWN = "unknown"@@ -31,7 +37,7 @@ class LLMProviderKey(UUIDTModel):ERROR = "error"team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE)- provider = models.CharField(max_length=50, choices=LLMProvider)+ provider = models.CharField(max_length=50, choices=llm_provider_choices)name = models.CharField(max_length=255)state = models.CharField(max_length=20, choices=State, default=State.UNKNOWN)error_message = models.TextField(null=True, blank=True)diff --git a/products/notifications/backend/migrations/0025_callable_choices.py b/products/notifications/backend/migrations/0025_callable_choices.pynew file mode 100644index 000000000000..39b00bf51ec7--- /dev/null+++ b/products/notifications/backend/migrations/0025_callable_choices.py@@ -0,0 +1,32 @@+# Generated by Django 5.2.17 on 2026-08-20 08:14++from django.db import migrations, models++import products.notifications.backend.models+import products.notifications.backend.facade.enums+++class Migration(migrations.Migration):+ dependencies = [+ ("notifications", "0024_alter_notificationevent_notification_type"),+ ]++ operations = [+ migrations.AlterField(+ model_name="notificationevent",+ name="notification_type",+ field=models.CharField(+ choices=products.notifications.backend.models.notification_type_choices,+ max_length=32,+ ),+ ),+ migrations.AlterField(+ model_name="notificationevent",+ name="priority",+ field=models.CharField(+ choices=products.notifications.backend.models.priority_choices,+ default=products.notifications.backend.facade.enums.Priority["NORMAL"],+ max_length=16,+ ),+ ),+ ]diff --git a/products/notifications/backend/migrations/max_migration.txt b/products/notifications/backend/migrations/max_migration.txtindex c6e0236aea7b..77f7766af773 100644--- a/products/notifications/backend/migrations/max_migration.txt+++ b/products/notifications/backend/migrations/max_migration.txt@@ -1 +1 @@-0024_alter_notificationevent_notification_type+0025_callable_choicesdiff --git a/products/notifications/backend/models.py b/products/notifications/backend/models.pyindex 85a9bb7c844b..0d47b5c7d334 100644--- a/products/notifications/backend/models.py+++ b/products/notifications/backend/models.py@@ -1,15 +1,25 @@from django.db import models+from django.utils.functional import Promisefrom posthog.models.utils import UUIDModelfrom products.notifications.backend.facade.enums import NotificationType, Priority, TargetType+def notification_type_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return [(t.value, t.name) for t in NotificationType]+++def priority_choices() -> list[tuple[str, str | Promise]]:+ return [(p.value, p.name) for p in Priority]++class NotificationEvent(UUIDModel):organization = models.ForeignKey("posthog.Organization", on_delete=models.CASCADE)team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, null=True, blank=True)- notification_type = models.CharField(max_length=32, choices=[(t.value, t.name) for t in NotificationType])- priority = models.CharField(max_length=16, choices=[(p.value, p.name) for p in Priority], default=Priority.NORMAL)+ notification_type = models.CharField(max_length=32, choices=notification_type_choices)+ priority = models.CharField(max_length=16, choices=priority_choices, default=Priority.NORMAL)title = models.CharField(max_length=255)body = models.TextField(blank=True, default="")resource_type = models.CharField(max_length=64, null=True, blank=True)diff --git a/products/replay_vision/backend/migrations/0081_callable_choices.py b/products/replay_vision/backend/migrations/0081_callable_choices.pynew file mode 100644index 000000000000..8d26794b9459--- /dev/null+++ b/products/replay_vision/backend/migrations/0081_callable_choices.py@@ -0,0 +1,20 @@+# Generated by Django 5.2.17 on 2026-08-20 08:14++from django.db import migrations, models++import products.replay_vision.backend.models.replay_scanner+++class Migration(migrations.Migration):+ dependencies = [("replay_vision", "0080_backfill_primed_at")]++ operations = [+ migrations.AlterField(+ model_name="replayscanner",+ name="model",+ field=models.CharField(+ choices=products.replay_vision.backend.models.replay_scanner.scanner_model_choices,+ max_length=64,+ ),+ ),+ ]diff --git a/products/replay_vision/backend/migrations/max_migration.txt b/products/replay_vision/backend/migrations/max_migration.txtindex cab4f8018ce3..521be0f76bb0 100644--- a/products/replay_vision/backend/migrations/max_migration.txt+++ b/products/replay_vision/backend/migrations/max_migration.txt@@ -1 +1 @@-0080_backfill_primed_at+0081_callable_choicesdiff --git a/products/replay_vision/backend/models/replay_scanner.py b/products/replay_vision/backend/models/replay_scanner.pyindex a723482f40ce..ab123402261d 100644--- a/products/replay_vision/backend/models/replay_scanner.py+++ b/products/replay_vision/backend/models/replay_scanner.py@@ -4,6 +4,7 @@ from typing import TYPE_CHECKINGfrom django.core.validators import MaxValueValidator, MinValueValidatorfrom django.db import models, transactionfrom django.utils import timezone+from django.utils.functional import Promisefrom posthog.models.utils import UUIDModel@@ -47,6 +48,11 @@ class ScannerModel(models.TextChoices):GEMINI_3_7_FLASH = "gemini-3.7-flash", "Gemini 3.7 Flash"+def scanner_model_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(ScannerModel.choices)++class ScannerOrigin(models.TextChoices):"""Where a scanner's config came from, and therefore what the row is allowed to do."""@@ -113,7 +119,7 @@ class ReplayScanner(UUIDModel):)provider = models.CharField(max_length=32, choices=ScannerProvider.choices, default=ScannerProvider.GOOGLE)- model = models.CharField(max_length=64, choices=ScannerModel.choices)+ model = models.CharField(max_length=64, choices=scanner_model_choices)enabled = models.BooleanField(default=True,diff --git a/products/review_hog/backend/migrations/0030_callable_choices.py b/products/review_hog/backend/migrations/0030_callable_choices.pynew file mode 100644index 000000000000..5be109028495--- /dev/null+++ b/products/review_hog/backend/migrations/0030_callable_choices.py@@ -0,0 +1,22 @@+# Generated by Django 5.2.17 on 2026-08-20 08:14++from django.db import migrations, models++import products.review_hog.backend.models+++class Migration(migrations.Migration):+ dependencies = [+ ("review_hog", "0029_alter_reviewreportartefact_type"),+ ]++ operations = [+ migrations.AlterField(+ model_name="reviewreportartefact",+ name="type",+ field=models.CharField(+ choices=products.review_hog.backend.models.review_report_artefact_type_choices,+ max_length=100,+ ),+ ),+ ]diff --git a/products/review_hog/backend/migrations/max_migration.txt b/products/review_hog/backend/migrations/max_migration.txtindex 391b0cd2d8d1..ab60b2f13b18 100644--- a/products/review_hog/backend/migrations/max_migration.txt+++ b/products/review_hog/backend/migrations/max_migration.txt@@ -1 +1 @@-0029_alter_reviewreportartefact_type+0030_callable_choicesdiff --git a/products/review_hog/backend/models.py b/products/review_hog/backend/models.pyindex d329528197d3..9f5c9d1b6504 100644--- a/products/review_hog/backend/models.py+++ b/products/review_hog/backend/models.py@@ -1,4 +1,5 @@from django.db import models+from django.utils.functional import Promisefrom posthog.models.scoping.root_mixin import TeamScopedRootMixinfrom posthog.models.utils import UUIDModel@@ -151,6 +152,11 @@ class ReviewReport(UUIDModel, TeamScopedRootMixin):]+def review_report_artefact_type_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(ReviewReportArtefact.ArtefactType.choices)++class ReviewReportArtefact(UUIDModel, TeamScopedRootMixin):"""Append-only work log for a `ReviewReport`.@@ -200,7 +206,7 @@ class ReviewReportArtefact(UUIDModel, TeamScopedRootMixin):# db_constraint=False keeps the migration lock-free on hot posthog_team.team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, related_name="+", db_constraint=False)report = models.ForeignKey(ReviewReport, on_delete=models.CASCADE, related_name="artefacts")- type = models.CharField(max_length=100, choices=ArtefactType)+ type = models.CharField(max_length=100, choices=review_report_artefact_type_choices)content = models.TextField()# Turn scope, denormalized from content.head_sha so resume loaders can filter in SQL instead of# parsing every historical row. Null when the content model carries no head_sha.diff --git a/products/signals/backend/enums.py b/products/signals/backend/enums.pyindex 5d28a0ca578e..ffd11e7d4268 100644--- a/products/signals/backend/enums.py+++ b/products/signals/backend/enums.py@@ -1,5 +1,7 @@from enum import StrEnum+from django.utils.functional import Promise+# Source-of-truth taxonomy for signals. Django-free (plain StrEnum) so it stays cheap to import# from contracts.py, the model layer, and the frontend-types codegen alike. StrEnum members compare# equal to their string value, so they drop into `==` checks and ORM filters unchanged.@@ -159,9 +161,9 @@ SIGNAL_SOURCE_PRODUCT_LABELS: dict[SignalSourceProduct, str] = {SignalSourceProduct.GOOGLE_SEARCH_CONSOLE: "Google Search Console",}-# The Django model's `source_product` choices, frozen-equivalent to the prior nested TextChoices so-# no migration is generated. Plain `str` values (not enum members) keep migration state stable; order++# The Django model's `source_product` choices. Callable so adding a product never lands in migration+# state as a no-op AlterField. Plain `str` values (not enum members) keep the state stable; order# follows SIGNAL_SOURCE_PRODUCT_LABELS, which matches the original declaration order.-SIGNAL_SOURCE_PRODUCT_CHOICES: list[tuple[str, str]] = [- (product.value, label) for product, label in SIGNAL_SOURCE_PRODUCT_LABELS.items()-]+def signal_source_product_choices() -> list[tuple[str, str | Promise]]:+ return [(product.value, label) for product, label in SIGNAL_SOURCE_PRODUCT_LABELS.items()]diff --git a/products/signals/backend/migrations/0100_callable_choices.py b/products/signals/backend/migrations/0100_callable_choices.pynew file mode 100644index 000000000000..4f3a15d440b8--- /dev/null+++ b/products/signals/backend/migrations/0100_callable_choices.py@@ -0,0 +1,39 @@+# Generated by Django 5.2.17 on 2026-08-20 08:14++from django.db import migrations, models++import products.signals.backend.enums+import products.signals.backend.models+++class Migration(migrations.Migration):+ dependencies = [+ ("signals", "0099_backfill_first_visible_at"),+ ]++ operations = [+ migrations.AlterField(+ model_name="signalreportartefact",+ name="type",+ field=models.CharField(+ choices=products.signals.backend.models.signal_report_artefact_type_choices,+ max_length=100,+ ),+ ),+ migrations.AlterField(+ model_name="signalsourceconfig",+ name="source_product",+ field=models.CharField(+ choices=products.signals.backend.enums.signal_source_product_choices,+ max_length=100,+ ),+ ),+ migrations.AlterField(+ model_name="signalsourceconfig",+ name="source_type",+ field=models.CharField(+ choices=products.signals.backend.models.signal_source_type_choices,+ max_length=100,+ ),+ ),+ ]diff --git a/products/signals/backend/migrations/max_migration.txt b/products/signals/backend/migrations/max_migration.txtindex 00bff8ffd2a9..400aae643d0f 100644--- a/products/signals/backend/migrations/max_migration.txt+++ b/products/signals/backend/migrations/max_migration.txt@@ -1 +1 @@-0099_backfill_first_visible_at+0100_callable_choicesdiff --git a/products/signals/backend/models.py b/products/signals/backend/models.pyindex dddadade8d02..763457d36628 100644--- a/products/signals/backend/models.py+++ b/products/signals/backend/models.py@@ -8,6 +8,7 @@ from django.contrib.postgres.indexes import GinIndexfrom django.core.validators import MaxValueValidator, MinValueValidatorfrom django.db import IntegrityError, models, transactionfrom django.utils import timezone+from django.utils.functional import Promisefrom asgiref.sync import async_to_syncfrom django_deprecate_fields import deprecate_field@@ -32,11 +33,16 @@ from products.signals.backend.artefact_schemas import (parse_artefact_content,task_run_identifier_for_legacy_relationship,)-from products.signals.backend.enums import SIGNAL_SOURCE_PRODUCT_CHOICES, SignalSourceProduct+from products.signals.backend.enums import SignalSourceProduct, signal_source_product_choiceslogger = logging.getLogger(__name__)+def signal_source_type_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(SignalSourceConfig.SourceType.choices)++class SignalSourceConfig(UUIDModel):# Source-product taxonomy is owned by products.signals.backend.enums (the same StrEnum the payload# contracts and frontend codegen use). Aliased here so `SignalSourceConfig.SourceProduct.X` keeps@@ -66,8 +72,8 @@ class SignalSourceConfig(UUIDModel):CI_DURATION_REGRESSION = "ci_duration_regression", "CI duration regression"team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, related_name="signal_source_configs")- source_product = models.CharField(max_length=100, choices=SIGNAL_SOURCE_PRODUCT_CHOICES)- source_type = models.CharField(max_length=100, choices=SourceType)+ source_product = models.CharField(max_length=100, choices=signal_source_product_choices)+ source_type = models.CharField(max_length=100, choices=signal_source_type_choices)enabled = models.BooleanField(default=True)config = models.JSONField(default=dict)created_at = models.DateTimeField(auto_now_add=True)@@ -834,6 +840,11 @@ class SignalEmissionRecord(UUIDModel):]+def signal_report_artefact_type_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(SignalReportArtefact.ArtefactType.choices)++class SignalReportArtefact(UUIDModel):class ArtefactType(models.TextChoices):VIDEO_SEGMENT = "video_segment"@@ -888,7 +899,7 @@ class SignalReportArtefact(UUIDModel):team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE)report = models.ForeignKey(SignalReport, on_delete=models.CASCADE, related_name="artefacts")- type = models.CharField(max_length=100, choices=ArtefactType)+ type = models.CharField(max_length=100, choices=signal_report_artefact_type_choices)content = models.TextField()created_at = models.DateTimeField(auto_now_add=True)# Nullable so the migration is a fast, rolling-deploy-safe `ADD COLUMN ... NULL`; `auto_now`diff --git a/products/tasks/backend/migrations/0103_callable_choices.py b/products/tasks/backend/migrations/0103_callable_choices.pynew file mode 100644index 000000000000..376f06658acd--- /dev/null+++ b/products/tasks/backend/migrations/0103_callable_choices.py@@ -0,0 +1,41 @@+# Generated by Django 5.2.17 on 2026-08-20 08:14++from django.db import migrations, models++import products.tasks.backend.models+++class Migration(migrations.Migration):+ dependencies = [("tasks", "0102_channel_system_role")]++ operations = [+ migrations.AlterField(+ model_name="loop",+ name="origin_product",+ field=models.CharField(+ choices=products.tasks.backend.models.task_origin_product_choices,+ default="user_created",+ help_text="Which product or flow created this loop.",+ max_length=32,+ ),+ ),+ migrations.AlterField(+ model_name="sandboxsession",+ name="origin_product",+ field=models.CharField(+ blank=True,+ choices=products.tasks.backend.models.task_origin_product_choices,+ help_text="Task origin at provision time, denormalized for per-origin aggregation",+ max_length=20,+ null=True,+ ),+ ),+ migrations.AlterField(+ model_name="task",+ name="origin_product",+ field=models.CharField(+ choices=products.tasks.backend.models.task_origin_product_choices,+ max_length=20,+ ),+ ),+ ]diff --git a/products/tasks/backend/migrations/max_migration.txt b/products/tasks/backend/migrations/max_migration.txtindex e23fe6916a34..51281f32f823 100644--- a/products/tasks/backend/migrations/max_migration.txt+++ b/products/tasks/backend/migrations/max_migration.txt@@ -1 +1 @@-0102_channel_system_role+0103_callable_choicesdiff --git a/products/tasks/backend/models.py b/products/tasks/backend/models.pyindex 8977d46078a2..e25c4485c977 100644--- a/products/tasks/backend/models.py+++ b/products/tasks/backend/models.py@@ -10,6 +10,7 @@ from typing import TYPE_CHECKING, Any, Literal, Optionalfrom django.db.models.signals import post_delete, post_save, pre_deletefrom django.dispatch import receiver+from django.utils.functional import Promisefrom pydantic import BaseModel@@ -203,6 +204,11 @@ class TaskClientProvenance(models.TextChoices):POSTHOG_DESKTOP = "posthog_desktop", "PostHog Desktop"+def task_origin_product_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(Task.OriginProduct.choices)++class Task(DeletedMetaFields, models.Model):class Runtime(models.TextChoices):ACP = "acp", "ACP"@@ -253,7 +259,7 @@ class Task(DeletedMetaFields, models.Model):title = models.CharField(max_length=255)title_manually_set = models.BooleanField(default=False)description = models.TextField()- origin_product = models.CharField(max_length=20, choices=OriginProduct)+ origin_product = models.CharField(max_length=20, choices=task_origin_product_choices)client_provenance = models.CharField(max_length=32,choices=TaskClientProvenance,@@ -1689,7 +1695,7 @@ class Loop(ModelActivityMixin, TeamScopedRootMixin):# ownership; the loop is still team- and owner-scoped via `team`/`created_by`).origin_product = models.CharField(max_length=32,- choices=Task.OriginProduct.choices,+ choices=task_origin_product_choices,default=Task.OriginProduct.USER_CREATED,help_text="Which product or flow created this loop.",)@@ -2909,7 +2915,7 @@ class SandboxSession(TeamScopedRootMixin, UUIDModel):sandbox_id = models.CharField(max_length=255, unique=True, help_text="Provider sandbox id (e.g. Modal object id)")origin_product = models.CharField(max_length=20,- choices=Task.OriginProduct,+ choices=task_origin_product_choices,null=True,blank=True,help_text="Task origin at provision time, denormalized for per-origin aggregation",diff --git a/products/warehouse_sources/backend/facade/types.py b/products/warehouse_sources/backend/facade/types.pyindex adee373c7220..d106e9c4f893 100644--- a/products/warehouse_sources/backend/facade/types.py+++ b/products/warehouse_sources/backend/facade/types.py@@ -12,6 +12,7 @@ import typingfrom enum import StrEnumfrom django.db import models+from django.utils.functional import Promise__all__ = ["DIRECT_ENGINE_BY_SOURCE_TYPE",@@ -1368,6 +1369,11 @@ class ExternalDataSourceType(models.TextChoices):KALSHI = "Kalshi", "Kalshi"+def external_data_source_type_choices() -> list[tuple[str, str | Promise]]:+ # Callable so growing the enum doesn't generate a no-op migration.+ return list(ExternalDataSourceType.choices)++# Maps a source type to the direct-SQL engine that can query it live. A source type is only# direct-query-capable if it appears here AND has an adapter registered in posthog/hogql/direct_sql.# Adding an engine = one entry here + one adapter module + one registry call.diff --git a/products/warehouse_sources/backend/migrations/0152_callable_choices.py b/products/warehouse_sources/backend/migrations/0152_callable_choices.pynew file mode 100644index 000000000000..57256e27c22f--- /dev/null+++ b/products/warehouse_sources/backend/migrations/0152_callable_choices.py@@ -0,0 +1,28 @@+# Generated by Django 5.2.17 on 2026-08-20 08:14++from django.db import migrations, models++import products.warehouse_sources.backend.facade.types+++class Migration(migrations.Migration):+ dependencies = [("warehouse_sources", "0151_repin_linkedin_ads_api_version")]++ operations = [+ migrations.AlterField(+ model_name="externaldatasource",+ name="source_type",+ field=models.CharField(+ choices=products.warehouse_sources.backend.facade.types.external_data_source_type_choices,+ max_length=128,+ ),+ ),+ migrations.AlterField(+ model_name="pendingsourcecredential",+ name="source_type",+ field=models.CharField(+ choices=products.warehouse_sources.backend.facade.types.external_data_source_type_choices,+ max_length=128,+ ),+ ),+ ]diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txtindex 8d8d20cb4615..ebb653a306b0 100644--- a/products/warehouse_sources/backend/migrations/max_migration.txt+++ b/products/warehouse_sources/backend/migrations/max_migration.txt@@ -1 +1 @@-0151_repin_linkedin_ads_api_version+0152_callable_choicesdiff --git a/products/warehouse_sources/backend/models/external_data_source.py b/products/warehouse_sources/backend/models/external_data_source.pyindex dff1c75bcae6..0b4b869b56e2 100644--- a/products/warehouse_sources/backend/models/external_data_source.py+++ b/products/warehouse_sources/backend/models/external_data_source.py@@ -14,6 +14,7 @@ from products.warehouse_sources.backend.types import (DIRECT_ENGINE_BY_SOURCE_TYPE,ExternalDataSourceType,ManagedWarehouseSQLMode,+ external_data_source_type_choices,)logger = structlog.get_logger(__name__)@@ -66,7 +67,7 @@ class ExternalDataSource(ModelActivityMixin, CreatedMetaFields, UpdatedMetaField# `status` is deprecated in favour of external_data_schema.statusstatus = models.CharField(max_length=400)- source_type = models.CharField(max_length=128, choices=ExternalDataSourceType)+ source_type = models.CharField(max_length=128, choices=external_data_source_type_choices)# Pinned vendor API version (opaque vendor label, e.g. a Stripe date version). NULL resolves# to the source's `default_version` at sync time. A dedicated column (not `job_inputs`) so the# pin is queryable via the `data_warehouse_sources` HogQL system table — `job_inputs` isdiff --git a/products/warehouse_sources/backend/models/pending_source_credential.py b/products/warehouse_sources/backend/models/pending_source_credential.pyindex b15588d3b259..58aa4a723d1f 100644--- a/products/warehouse_sources/backend/models/pending_source_credential.py+++ b/products/warehouse_sources/backend/models/pending_source_credential.py@@ -7,7 +7,7 @@ from posthog.helpers.encrypted_fields import EncryptedJSONFieldfrom posthog.models.scoping.root_mixin import TeamScopedRootMixinfrom posthog.models.utils import CreatedMetaFields, UUIDTModel, sane_repr-from products.warehouse_sources.backend.types import ExternalDataSourceType+from products.warehouse_sources.backend.types import external_data_source_type_choicesPENDING_CREDENTIAL_TTL = timedelta(hours=24)@@ -25,7 +25,7 @@ class PendingSourceCredential(TeamScopedRootMixin, CreatedMetaFields, UUIDTModel"""team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE)- source_type = models.CharField(max_length=128, choices=ExternalDataSourceType)+ source_type = models.CharField(max_length=128, choices=external_data_source_type_choices)payload = EncryptedJSONField(default=dict)expires_at = models.DateTimeField(default=pending_credential_default_expiry)diff --git a/products/warehouse_sources/backend/types.py b/products/warehouse_sources/backend/types.pyindex f3182da2437d..f7c4057e45d3 100644--- a/products/warehouse_sources/backend/types.py+++ b/products/warehouse_sources/backend/types.py@@ -9,4 +9,5 @@ from products.warehouse_sources.backend.facade.types import (IncrementalFieldType as IncrementalFieldType,ManagedWarehouseSQLMode as ManagedWarehouseSQLMode,PartitionSettings as PartitionSettings,+ external_data_source_type_choices as external_data_source_type_choices,)