: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(cdp): allow creating functions from deprecated templates via the api (#98112)
Meikel Ratza54853d1f96a
diff --git a/posthog/cdp/migrations.py b/posthog/cdp/migrations.pyindex 6871b5558cda..8f330ad4fc87 100644--- a/posthog/cdp/migrations.py+++ b/posthog/cdp/migrations.py@@ -81,9 +81,6 @@ def migrate_batch(legacy_plugins: Any, kind: str, test_mode: bool, dry_run: bool"team": team,"get_team": (lambda t=team: t),"is_create": True,- # The plugin templates this migrates from are deprecated, which the serializer- # otherwise blocks on create.- "allow_deprecated_template": True,}template = HogFunctionTemplate.objects.get(template_id=f"plugin-{plugin_id}")diff --git a/products/cdp/backend/api/hog_function.py b/products/cdp/backend/api/hog_function.pyindex f2c679d17739..efd45455dc73 100644--- a/products/cdp/backend/api/hog_function.py+++ b/products/cdp/backend/api/hog_function.py@@ -464,15 +464,6 @@ class HogFunctionSerializer(HogFunctionMinimalSerializer):"template_id": f"Template '{template.template_id}' is internal and cannot be used to create a function."})- # Deprecated templates are only hidden from the template listing, so a direct API call with the- # template id could still create one. Block that too; existing functions keep running, and the- # legacy plugin migration (posthog/cdp/migrations.py) is the one internal caller allowed through.- if template.status == "deprecated" and not self.context.get("allow_deprecated_template"):- raise serializers.ValidationError(- {- "template_id": f"Template '{template.template_id}' is deprecated and cannot be used to create a new function."- }- )def _validate_hidden_template_not_enabled(self, attrs: dict, is_create: bool) -> None:# Creating from a hidden template is already blocked outright. For an existing function built fromdiff --git a/products/cdp/backend/api/test/test_hog_function.py b/products/cdp/backend/api/test/test_hog_function.pyindex ddbc9385d6f7..579897839639 100644--- a/products/cdp/backend/api/test/test_hog_function.py+++ b/products/cdp/backend/api/test/test_hog_function.py@@ -364,9 +364,9 @@ class TestHogFunctionAPI(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):assert response.json()["attr"] == "template_id"assert not HogFunction.objects.filter(template_id="template-hidden-dest").exists()- def test_create_from_deprecated_template_is_blocked(self):- # Deprecated templates are excluded from the template listing but stay resolvable by id,- # so the create path must reject them explicitly.+ def test_create_from_deprecated_template_is_allowed(self):+ # Deprecated templates are hidden from the listing but stay resolvable by id, so the API must+ # keep creating from them - integrations reference legacy plugin template ids directly.HogFunctionTemplate.objects.create(template_id="plugin-deprecated-transformation",sha="1.0.0",@@ -389,10 +389,8 @@ class TestHogFunctionAPI(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):"inputs": {},},)- assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()- assert response.json()["attr"] == "template_id"- assert "deprecated" in response.json()["detail"]- assert not HogFunction.objects.filter(template_id="plugin-deprecated-transformation").exists()+ assert response.status_code == status.HTTP_201_CREATED, response.json()+ assert HogFunction.objects.filter(template_id="plugin-deprecated-transformation").exists()@parameterized.expand([