: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(admin): register moved hogflow and cdp admins via package init (#60652)
Daniel Marchukcb5b59f6da85
diff --git a/posthog/admin/test_admin.py b/posthog/admin/test_admin.pyindex 58350158aa20..30bb1ada612d 100644--- a/posthog/admin/test_admin.py+++ b/posthog/admin/test_admin.py@@ -1,3 +1,4 @@+import pytestfrom posthog.test.base import BaseTestfrom unittest.mock import MagicMock, patch@@ -5,7 +6,7 @@ from django.contrib import adminfrom django.contrib.admin import AdminSitefrom django.test import RequestFactory-from posthog.admin import _OAUTH_ADMIN_MODEL_NAMES, install_admin_app_list_overrides+from posthog.admin import _OAUTH_ADMIN_MODEL_NAMES, install_admin_app_list_overrides, register_all_adminfrom posthog.admin.admins.event_ingestion_restriction_config import EventIngestionRestrictionConfigAdminfrom posthog.admin.admins.user_admin import UserAdmin, UserChangeFormfrom posthog.admin.inlines.organization_member_inline import OrganizationMemberForUserInline, OrganizationMemberInline@@ -13,6 +14,11 @@ from posthog.models import Userfrom posthog.models.event_ingestion_restriction_config import EventIngestionRestrictionConfigfrom products.cdp.backend.admin.plugin_attachment_inline import PluginAttachmentInline+from products.cdp.backend.models.hog_functions.hog_function import HogFunction+from products.cdp.backend.models.plugin import Plugin, PluginConfig+from products.workflows.backend.models.hog_flow.hog_flow import HogFlow+from products.workflows.backend.models.hog_flow.hog_flow_template import HogFlowTemplate+from products.workflows.backend.models.hog_flow_batch_job import HogFlowBatchJobclass TestOAuthSidebarRegrouping(BaseTest):@@ -172,6 +178,23 @@ class TestEventIngestionRestrictionConfigAdminConfig:assert "display_team_id" in admin_instance.readonly_fields+class TestProductAdminRegistration:+ # Regression guard: these models live in product apps (`products/cdp`,+ # `products/workflows`) whose admin classes are split across submodules of an+ # `admin/` package. `autodiscover_modules("admin")` only imports the package's+ # `__init__`, so it must import those submodules for the `@admin.register`+ # decorators to fire — otherwise the models silently vanish from Django admin.+ @pytest.mark.parametrize(+ "model",+ [HogFlow, HogFlowTemplate, HogFlowBatchJob, HogFunction, Plugin, PluginConfig],+ ids=lambda m: m.__name__,+ )+ def test_moved_product_models_are_registered(self, model):+ # Tests skip the lazy admin registry, so trigger registration explicitly.+ register_all_admin()+ assert admin.site.is_registered(model), f"{model.__name__} is not registered in Django admin"++class TestOrganizationMemberInlineConfig(BaseTest):def test_invited_by_is_readonly_and_never_rendered_as_user_select(self):# Regression guard: invited_by must not become an editable FK select in admin inlines.diff --git a/products/cdp/backend/admin/__init__.py b/products/cdp/backend/admin/__init__.pyindex e69de29bb2d1..4aa779f3eb34 100644--- a/products/cdp/backend/admin/__init__.py+++ b/products/cdp/backend/admin/__init__.py@@ -0,0 +1,3 @@+# Importing these submodules fires their `@admin.register` decorators when+# `autodiscover_modules("admin")` imports this package.+from products.cdp.backend.admin import hog_function_admin, plugin_admin, plugin_config_admin # noqa: F401diff --git a/products/workflows/backend/admin/__init__.py b/products/workflows/backend/admin/__init__.pyindex e69de29bb2d1..f21ddb6a9db2 100644--- a/products/workflows/backend/admin/__init__.py+++ b/products/workflows/backend/admin/__init__.py@@ -0,0 +1,7 @@+# Importing these submodules fires their `@admin.register` decorators when+# `autodiscover_modules("admin")` imports this package.+from products.workflows.backend.admin import ( # noqa: F401+ hog_flow_admin,+ hog_flow_batch_job_admin,+ hog_flow_template_admin,+)diff --git a/products/workflows/backend/admin/hog_flow_batch_job_admin.py b/products/workflows/backend/admin/hog_flow_batch_job_admin.pynew file mode 100644index 000000000000..bbaff8aeecf0--- /dev/null+++ b/products/workflows/backend/admin/hog_flow_batch_job_admin.py@@ -0,0 +1,55 @@+from django.contrib import admin+from django.urls import reverse+from django.utils.html import format_html++from products.workflows.backend.models.hog_flow_batch_job import HogFlowBatchJob++[email protected](HogFlowBatchJob)+class HogFlowBatchJobAdmin(admin.ModelAdmin):+ list_display = ("id", "status", "hog_flow_link", "team_link", "created_at")+ list_filter = (+ ("status", admin.ChoicesFieldListFilter),+ ("updated_at", admin.DateFieldListFilter),+ )+ list_select_related = ("team", "hog_flow")+ search_fields = ("hog_flow__name", "team__name", "team__organization__name")+ ordering = ("-created_at",)+ readonly_fields = (+ "id",+ "team",+ "team_link",+ "hog_flow",+ "hog_flow_link",+ "created_by",+ "created_at",+ "updated_at",+ "variables",+ "filters",+ )+ fields = (+ "status",+ "team_link",+ "hog_flow_link",+ "created_by",+ "created_at",+ "updated_at",+ "variables",+ "filters",+ )++ @admin.display(description="Team")+ def team_link(self, batch_job: HogFlowBatchJob):+ return format_html(+ '<a href="{}">{}</a>',+ reverse("admin:posthog_team_change", args=[batch_job.team.pk]),+ batch_job.team.name,+ )++ @admin.display(description="Hog flow")+ def hog_flow_link(self, batch_job: HogFlowBatchJob):+ return format_html(+ '<a href="{}">{}</a>',+ reverse("admin:workflows_hogflow_change", args=[batch_job.hog_flow.pk]),+ batch_job.hog_flow.name or batch_job.hog_flow.pk,+ )diff --git a/products/workflows/backend/admin/hog_flow_template_admin.py b/products/workflows/backend/admin/hog_flow_template_admin.pynew file mode 100644index 000000000000..807a16c61a27--- /dev/null+++ b/products/workflows/backend/admin/hog_flow_template_admin.py@@ -0,0 +1,58 @@+from django.contrib import admin+from django.urls import reverse+from django.utils.html import format_html++from products.workflows.backend.models.hog_flow.hog_flow_template import HogFlowTemplate++[email protected](HogFlowTemplate)+class HogFlowTemplateAdmin(admin.ModelAdmin):+ list_display = ("id", "name", "scope", "team_link", "created_at")+ list_filter = (+ ("scope", admin.ChoicesFieldListFilter),+ ("updated_at", admin.DateFieldListFilter),+ )+ list_select_related = ("team",)+ search_fields = ("name", "team__name", "team__organization__name")+ ordering = ("-created_at",)+ readonly_fields = (+ "id",+ "team",+ "team_link",+ "created_by",+ "created_at",+ "updated_at",+ "trigger",+ "trigger_masking",+ "conversion",+ "edges",+ "actions",+ "variables",+ )+ fields = (+ "name",+ "description",+ "image_url",+ "tags",+ "scope",+ "exit_condition",+ "abort_action",+ "team_link",+ "created_by",+ "created_at",+ "updated_at",+ "trigger",+ "trigger_masking",+ "conversion",+ "edges",+ "actions",+ "variables",+ )++ @admin.display(description="Team")+ def team_link(self, template: HogFlowTemplate):+ return format_html(+ '<a href="{}">{}</a>',+ reverse("admin:posthog_team_change", args=[template.team.pk]),+ template.team.name,+ )