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.

fix(data-modeling): resolve cadence-tier schedule ids to their DAG id (#67547)

Jovan Sakovic94a4e3bcf333
diff --git a/products/data_modeling/backend/management/commands/delete_orphaned_saved_query_schedules.py b/products/data_modeling/backend/management/commands/delete_orphaned_saved_query_schedules.py
index c080615ec30f..f152dcc80bba 100644
--- a/products/data_modeling/backend/management/commands/delete_orphaned_saved_query_schedules.py
+++ b/products/data_modeling/backend/management/commands/delete_orphaned_saved_query_schedules.py
@@ -130,6 +130,11 @@ class Command(BaseCommand):
valid_uuids: set[str] = set()
for sid in target_ids:
+ if ":" in sid:
+ # "{dag_id}:{interval_seconds}" is a v2 cadence-tier execute-dag schedule,
+ # not a saved-query schedule — never sweep it as an orphan.
+ logger.warning("v2 cadence-tier schedule id, skipping", schedule_id=sid)
+ continue
try:
UUID(sid)
valid_uuids.add(sid)
diff --git a/products/data_modeling/backend/schedule.py b/products/data_modeling/backend/schedule.py
index 2ea58c04015a..fc571ae34a25 100644
--- a/products/data_modeling/backend/schedule.py
+++ b/products/data_modeling/backend/schedule.py
@@ -33,7 +33,8 @@ from products.data_modeling.backend.models import Node
if TYPE_CHECKING:
from products.data_modeling.backend.models.datawarehouse_saved_query import DataWarehouseSavedQuery
-# v2 (DAG-based) schedules run this workflow; their schedule id is the DAG id. The v1 backend
+# v2 (DAG-based) schedules run this workflow; their schedule id is the bare DAG id, or
+# "{dag_id}:{interval_seconds}" for a per-cadence-tier schedule. The v1 backend
# (`data-modeling-run`, one schedule per saved query) is frozen and being migrated away from.
DATA_MODELING_EXECUTE_DAG_WORKFLOW = "data-modeling-execute-dag"
@@ -84,7 +85,9 @@ async def get_v2_scheduled_dag_ids(candidate_dag_ids: Collection[str] | None = N
isinstance(action, ScheduleListActionStartWorkflow)
and action.workflow == DATA_MODELING_EXECUTE_DAG_WORKFLOW
):
- dag_ids.add(listing.id)
+ # A cadence-tier schedule id is "{dag_id}:{interval_seconds}"; a legacy id is the
+ # bare DAG id (no colon), which rsplit leaves untouched.
+ dag_ids.add(listing.id.rsplit(":", 1)[0])
return dag_ids
diff --git a/products/data_modeling/backend/test/test_delete_orphaned_saved_query_schedules.py b/products/data_modeling/backend/test/test_delete_orphaned_saved_query_schedules.py
new file mode 100644
index 000000000000..c78b5afd60b2
--- /dev/null
+++ b/products/data_modeling/backend/test/test_delete_orphaned_saved_query_schedules.py
@@ -0,0 +1,11 @@
+from asgiref.sync import async_to_sync
+
+from products.data_modeling.backend.management.commands.delete_orphaned_saved_query_schedules import Command
+
+
+class TestFindOrphansFromIds:
+ def test_tier_schedule_ids_are_never_orphans(self):
+ # "{dag_id}:{seconds}" is a live v2 cadence-tier schedule; treating it as an orphan
+ # (the non-UUID fallback) would delete active DAG scheduling on operator input
+ orphans = async_to_sync(Command()._find_orphans_from_ids)({"018f2a00-0000-0000-0000-000000000000:900"})
+ assert orphans == set()
diff --git a/products/data_modeling/backend/test/test_schedule.py b/products/data_modeling/backend/test/test_schedule.py
index 151977b3a004..8e058e97e3e8 100644
--- a/products/data_modeling/backend/test/test_schedule.py
+++ b/products/data_modeling/backend/test/test_schedule.py
@@ -373,6 +373,32 @@ class TestGetV2ScheduledDagIds:
assert captured["kwargs"]["query"] == "PostHogDagId IN ('dag-on-v2')"
assert result == {"dag-on-v2"}
+ def test_tiered_schedule_ids_resolve_to_the_dag_id(self):
+ # cadence-tier schedules are "{dag_id}:{seconds}"; returning them raw would make every
+ # v2-detection consumer treat migrated DAGs as v1 and recreate v1 schedules
+ listings = [
+ self._listing("dag-a:900", "data-modeling-execute-dag"),
+ self._listing("dag-a:86400", "data-modeling-execute-dag"),
+ self._listing("dag-b", "data-modeling-execute-dag"),
+ ]
+
+ async def fake_list_schedules(*args, **kwargs):
+ async def gen():
+ for listing in listings:
+ yield listing
+
+ return gen()
+
+ temporal = mock.Mock()
+ temporal.list_schedules = fake_list_schedules
+ with mock.patch(
+ "products.data_modeling.backend.schedule.async_connect",
+ new=mock.AsyncMock(return_value=temporal),
+ ):
+ result = get_v2_scheduled_dag_ids()
+
+ assert result == {"dag-a", "dag-b"}
+
def test_empty_candidates_skips_temporal(self):
connect = mock.AsyncMock()
with mock.patch("products.data_modeling.backend.schedule.async_connect", new=connect):