Skip to content

: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.

chore(cdp): remove fully rolled out destinations-revisions flag (#87714)

Meikel Ratz2c504e40ff8c
diff --git a/products/cdp/backend/api/hog_function.py b/products/cdp/backend/api/hog_function.py
index f42e0a5f0873..20efcc870bb4 100644
--- a/products/cdp/backend/api/hog_function.py
+++ b/products/cdp/backend/api/hog_function.py
@@ -66,7 +66,6 @@ from products.cdp.backend.models.hog_functions.hog_function import (
from products.cdp.backend.models.hog_functions.hog_function_revision import HogFunctionRevision
from products.cdp.backend.models.hog_functions.utils import humanize_hog_function_type
from products.cdp.backend.models.plugin import TranspilerError
-from products.cdp.backend.services.revisions import use_destinations_revisions
# Maximum size of HOG code as a string in bytes (100KB)
MAX_HOG_CODE_SIZE_BYTES = 100 * 1024
@@ -103,8 +102,6 @@ _DERIVED_CONTENT_FIELDS = frozenset({"bytecode", "transpiled"})
# validated_data says nothing about what the caller actually asked to change.
_INJECTED_UPDATE_FIELDS = frozenset({"team", "type", "template_id"})
-DRAFTS_DISABLED_MESSAGE = "Drafts aren't enabled for this project yet."
-REVISIONS_DISABLED_MESSAGE = "Revision history isn't enabled for this project yet."
ENABLE_WITH_OPEN_DRAFT_MESSAGE = (
"This function has config staged for review. Publish or discard it before enabling, so you don't "
"turn on config nobody looked at."
@@ -1115,8 +1112,6 @@ class HogFunctionViewSet(
fields on top, staged secrets rehydrated in plaintext so the test exercises what publish
would ship. Secrets the draft doesn't stage stay as `{"secret": true}` markers, which
validation recovers from the live encrypted inputs."""
- if not use_destinations_revisions(self.team):
- raise exceptions.ValidationError(DRAFTS_DISABLED_MESSAGE)
if hog_function is None or not hog_function.draft:
raise exceptions.ValidationError({"use_draft": "This function has no staged draft to test."})
@@ -1243,7 +1238,6 @@ class HogFunctionViewSet(
serializer.validated_data.get("enabled")
and (serializer.validated_data.get("type") or HogFunctionType.DESTINATION) == HogFunctionType.DESTINATION
and self._is_agent_request(self.request)
- and use_destinations_revisions(self.team)
):
raise exceptions.ValidationError({"enabled": CREATE_ENABLED_MESSAGE})
serializer.save()
@@ -1265,14 +1259,14 @@ class HogFunctionViewSet(
# with the live ones.
return set(self.request.data.keys()) & set(DRAFT_CONTENT_FIELDS)
- def _should_route_to_draft(self, serializer: BaseSerializer, revisions_enabled: bool) -> bool:
+ def _should_route_to_draft(self, serializer: BaseSerializer) -> bool:
# Guardrail for agent callers (MCP and the surfaces that wrap it; the web builder and raw API
# keys are unaffected). An agent editing a destination that is running right now stages a
# draft for a human to publish instead of changing what workers execute on the spot.
# Destinations only for now: transformations add execution-order semantics, site_* types add
# transpiled-JS concerns, and internal_destination rows are written by other products' code
# rather than by agents.
- if not revisions_enabled or not self._is_agent_request(self.request):
+ if not self._is_agent_request(self.request):
return False
instance = serializer.instance
if not isinstance(instance, HogFunction) or not instance.enabled:
@@ -1349,18 +1343,15 @@ class HogFunctionViewSet(
def perform_update(self, serializer):
instance_id = serializer.instance.id
- # Resolved before the write transaction: the flag check can hit the network and must not
- # extend the row lock.
- revisions_enabled = use_destinations_revisions(self.team)
- route_to_draft = self._should_route_to_draft(serializer, revisions_enabled)
+ # Resolved before the write transaction so the routing decision doesn't extend the row lock.
+ route_to_draft = self._should_route_to_draft(serializer)
# Enabling with a draft open would turn on the live config while the reviewed one sits
# unpublished. Make the caller resolve the draft first rather than picking for them.
# Checked on the validated value: BooleanField coerces "true"/"True", and the raw payload
# wouldn't catch those.
if (
- revisions_enabled
- and serializer.validated_data.get("enabled") is True
+ serializer.validated_data.get("enabled") is True
and isinstance(serializer.instance, HogFunction)
and serializer.instance.draft
and not serializer.instance.enabled
@@ -1424,7 +1415,7 @@ class HogFunctionViewSet(
else:
before_content = snapshot_hog_function_content(locked) if locked else None
serializer.save()
- if locked is not None and before_content is not None and revisions_enabled:
+ if locked is not None and before_content is not None:
self._record_revision(serializer.instance, locked, before_content)
log_activity_from_viewset(
@@ -1441,9 +1432,6 @@ class HogFunctionViewSet(
def publish(self, request: Request, *args, **kwargs):
# Promote the staged draft to the live config. Two-step by design: a call without confirm only
# echoes what would change, so callers — especially agents — never publish blind.
- if not use_destinations_revisions(self.team):
- raise exceptions.ValidationError(DRAFTS_DISABLED_MESSAGE)
-
param_serializer = HogFunctionPublishRequestSerializer(data=request.data)
param_serializer.is_valid(raise_exception=True)
@@ -1550,9 +1538,6 @@ class HogFunctionViewSet(
@action(detail=True, methods=["POST"])
def discard_draft(self, request: Request, *args, **kwargs):
# Throw away the staged draft. Idempotent: discarding when nothing is staged is a no-op.
- if not use_destinations_revisions(self.team):
- raise exceptions.ValidationError(DRAFTS_DISABLED_MESSAGE)
-
instance = self.get_object()
with transaction.atomic():
# nosemgrep: idor-lookup-without-team (re-fetch of already-authorized instance, locked for update)
@@ -1585,8 +1570,6 @@ class HogFunctionViewSet(
def revisions(self, request: Request, *args, **kwargs):
# Version history: one snapshot per live-config change, newest first. Config is fetched
# per-version via the detail endpoint — the list stays light.
- if not use_destinations_revisions(self.team):
- raise exceptions.ValidationError(REVISIONS_DISABLED_MESSAGE)
instance = self.get_object()
queryset = (
HogFunctionRevision.objects.filter(hog_function=instance).order_by("-version").select_related("created_by")
@@ -1601,8 +1584,6 @@ class HogFunctionViewSet(
)
@action(detail=True, methods=["GET"], url_path=r"revisions/(?P<version>\d+)", filter_backends=[])
def revision_detail(self, request: Request, version: Optional[str] = None, *args, **kwargs):
- if not use_destinations_revisions(self.team):
- raise exceptions.ValidationError(REVISIONS_DISABLED_MESSAGE)
instance = self.get_object()
try:
revision = HogFunctionRevision.objects.get(hog_function=instance, version=int(version or 0))
@@ -1623,8 +1604,6 @@ class HogFunctionViewSet(
# Rollback (or roll-forward) = copy the revision's config into the draft, then go through the
# normal publish preview + confirm. Nothing here touches the live config, so a rollback is
# reviewed like any other change.
- if not use_destinations_revisions(self.team):
- raise exceptions.ValidationError(REVISIONS_DISABLED_MESSAGE)
param_serializer = HogFunctionRevisionRestoreRequestSerializer(data=request.data)
param_serializer.is_valid(raise_exception=True)
diff --git a/products/cdp/backend/api/test/test_hog_function_drafts.py b/products/cdp/backend/api/test/test_hog_function_drafts.py
index 0d6d0535a5a4..619376cd46f1 100644
--- a/products/cdp/backend/api/test/test_hog_function_drafts.py
+++ b/products/cdp/backend/api/test/test_hog_function_drafts.py
@@ -6,10 +6,10 @@ from rest_framework import status
from posthog.models.activity_logging.activity_log import ActivityLog
+from products.cdp.backend.api.hog_function import HogFunctionViewSet
from products.cdp.backend.models.hog_functions.hog_function import HogFunction
from products.cdp.backend.models.hog_functions.hog_function_revision import HogFunctionRevision
-FLAG_PATH = "products.cdp.backend.api.hog_function.use_destinations_revisions"
RELOAD_PATH = "products.cdp.backend.models.hog_functions.hog_function.reload_hog_functions_on_workers"
LIVE_HOG = "fetch(inputs.url);"
@@ -29,12 +29,6 @@ BASE_FUNCTION = {
class DraftTestCase(APIBaseTest):
- def setUp(self):
- super().setUp()
- flag = patch(FLAG_PATH, return_value=True)
- flag.start()
- self.addCleanup(flag.stop)
-
def _url(self, function_id: str = "", suffix: str = "") -> str:
base = f"/api/projects/{self.team.id}/hog_functions/"
return f"{base}{function_id}{suffix}" if function_id else base
@@ -112,23 +106,20 @@ class TestHogFunctionDrafts(DraftTestCase):
[
# An agent can't stage a draft on a function that isn't running, and the web builder
# saves what the person just reviewed, so neither routes to a draft.
- ("disabled_function", True, {"enabled": False}, True),
- ("web_caller", False, {}, True),
+ ("disabled_function", True, {"enabled": False}),
+ ("web_caller", False, {}),
# Only destinations are in the cycle for now. A transformation edit still applies live.
- ("transformation", True, {"type": "transformation", "hog": "return event"}, True),
- # The flag is the kill switch: off means the pre-draft behavior, edits apply live.
- ("flag_off", True, {}, False),
+ ("transformation", True, {"type": "transformation", "hog": "return event"}),
]
)
- def test_config_edit_applies_live(self, _name: str, from_agent: bool, overrides: dict, flag_on: bool):
+ def test_config_edit_applies_live(self, _name: str, from_agent: bool, overrides: dict):
function_id = self._create(**overrides)
- with patch(FLAG_PATH, return_value=flag_on):
- response = (
- self._agent_patch(function_id, {"hog": EDITED_HOG})
- if from_agent
- else self.client.patch(self._url(function_id), {"hog": EDITED_HOG})
- )
+ response = (
+ self._agent_patch(function_id, {"hog": EDITED_HOG})
+ if from_agent
+ else self.client.patch(self._url(function_id), {"hog": EDITED_HOG})
+ )
assert response.status_code == status.HTTP_200_OK, response.json()
assert response.json()["draft"] is None
@@ -148,14 +139,15 @@ class TestHogFunctionDrafts(DraftTestCase):
def test_metadata_in_a_draft_edit_does_not_revert_a_concurrent_live_edit(self):
function_id = self._create()
concurrent_hog = "fetch(inputs.url, {'method': 'DELETE'});"
+ real_should_route_to_draft = HogFunctionViewSet._should_route_to_draft
- def live_edit_lands_after_initial_fetch(_team):
+ def live_edit_lands_after_initial_fetch(viewset, serializer):
# Stand in for a builder edit committing between the request's initial unlocked fetch
- # and its write: the flag check runs after get_object() and before the transaction.
+ # and its write: draft routing resolves after get_object() and before the transaction.
HogFunction.objects.filter(id=function_id).update(hog=concurrent_hog)
- return True
+ return real_should_route_to_draft(viewset, serializer)
- with patch(FLAG_PATH, side_effect=live_edit_lands_after_initial_fetch):
+ with patch.object(HogFunctionViewSet, "_should_route_to_draft", live_edit_lands_after_initial_fetch):
response = self._agent_patch(function_id, {"name": "Renamed", "hog": EDITED_HOG})
assert response.status_code == status.HTTP_200_OK, response.json()
@@ -450,16 +442,14 @@ class TestHogFunctionRevisions(DraftTestCase):
[
# `to_internal_value` re-injects inputs/filters and the serializer recompiles bytecode on
# every save, so an unchanged config must still compare equal and stay unversioned.
- ("metadata_only", {"name": "Renamed"}, True),
- ("config_resent_unchanged", {"hog": LIVE_HOG, "name": "Renamed"}, True),
- ("flag_off", {"hog": EDITED_HOG}, False),
+ ("metadata_only", {"name": "Renamed"}),
+ ("config_resent_unchanged", {"hog": LIVE_HOG, "name": "Renamed"}),
]
)
- def test_no_revision_is_written(self, _name: str, payload: dict, flag_on: bool):
+ def test_no_revision_is_written(self, _name: str, payload: dict):
function_id = self._create()
- with patch(FLAG_PATH, return_value=flag_on):
- self._live_edit(function_id, payload)
+ self._live_edit(function_id, payload)
assert not self._revisions(function_id).exists()
assert HogFunction.objects.get(id=function_id).version == 1
@@ -529,20 +519,3 @@ class TestHogFunctionRevisions(DraftTestCase):
restored_draft = HogFunction.objects.get(id=function_id).draft
assert restored_draft is not None
assert restored_draft["hog"] == LIVE_HOG
-
- @parameterized.expand(
- [
- ("publish", "post", "/publish"),
- ("discard_draft", "post", "/discard_draft"),
- ("revisions", "get", "/revisions"),
- ("revision_detail", "get", "/revisions/1"),
- ("restore_revision", "post", "/revisions/1/restore"),
- ]
- )
- def test_endpoints_are_rejected_when_the_flag_is_off(self, _name: str, method: str, suffix: str):
- function_id = self._create()
-
- with patch(FLAG_PATH, return_value=False):
- response = getattr(self.client, method)(self._url(function_id, suffix))
-
- assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()
diff --git a/products/cdp/backend/services/revisions.py b/products/cdp/backend/services/revisions.py
deleted file mode 100644
index 5c91b25b0189..000000000000
--- a/products/cdp/backend/services/revisions.py
+++ /dev/null
@@ -1,37 +0,0 @@
-import structlog
-import posthoganalytics
-
-from posthog.models.team.team import Team
-
-logger = structlog.get_logger(__name__)
-
-DESTINATIONS_REVISIONS_FLAG = "destinations-revisions"
-
-
-def use_destinations_revisions(team: Team) -> bool:
- """Gates the draft → review → publish cycle on enabled functions; off means today's behavior
- (every edit lands straight on the live config that workers execute).
-
- A raised exception (Redis/HyperCache blip, network glitch, SDK bug) is treated as "flag off" so
- the flag is a kill switch: edits keep applying live, exactly as they did before this shipped.
- """
- try:
- return bool(
- posthoganalytics.feature_enabled(
- DESTINATIONS_REVISIONS_FLAG,
- str(team.uuid),
- groups={"organization": str(team.organization_id), "project": str(team.id)},
- group_properties={
- "organization": {"id": str(team.organization_id)},
- "project": {"id": str(team.id)},
- },
- )
- )
- except Exception:
- logger.warning(
- "cdp.revisions.feature_flag_check_failed_defaulting_off",
- team_id=team.id,
- flag=DESTINATIONS_REVISIONS_FLAG,
- exc_info=True,
- )
- return False