: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(data-modeling): sweep legacy schedule on DAGs with no schedulable nodes (#75120)
Jovan Sakovic9edcf25c3fd4
diff --git a/products/data_modeling/backend/logic/schedule_reconcile.py b/products/data_modeling/backend/logic/schedule_reconcile.pyindex e392c8b73c7f..946281cf2417 100644--- a/products/data_modeling/backend/logic/schedule_reconcile.py+++ b/products/data_modeling/backend/logic/schedule_reconcile.py@@ -177,10 +177,12 @@ def reconcile_dag_schedules(dag: DAG, *, require_tiered: bool = False, graph: Fr"""Make Temporal's schedules for this DAG match its nodes' effective cadences.Converging a covered DAG to zero schedules is refused only while it still has just legacy- (non-tier) schedules — an empty tier set there almost always means unseeded targets. Once tier- schedules exist, an empty tier set is a deliberate wind-down (last target reverted/cleared) and- those tiers are torn down. With `require_tiered`, a DAG that has no tiered schedule yet (legacy- single schedule or nothing) is left untouched.+ (non-tier) schedules AND schedulable nodes — an empty tier set there almost always means+ unseeded targets. A DAG with no schedulable nodes has nothing to seed, so its legacy schedule+ is swept rather than left firing no-op runs. Once tier schedules exist, an empty tier set is a+ deliberate wind-down (last target reverted/cleared) and those tiers are torn down. With+ `require_tiered`, a DAG that has no tiered schedule yet (legacy single schedule or nothing) is+ left untouched."""team = dag.teamif graph is None:@@ -197,6 +199,7 @@ def reconcile_dag_schedules(dag: DAG, *, require_tiered: bool = False, graph: Frteam_timezone=team.timezone,desired_tiers=desired_tiers,require_tiered=require_tiered,+ has_schedulable_nodes=bool(graph.nodes),)@@ -321,6 +324,7 @@ async def _apply_reconciliation(team_timezone: str,desired_tiers: dict[timedelta, set[str]],require_tiered: bool = False,+ has_schedulable_nodes: bool = True,) -> None:unsupported = sorted(interval for interval in desired_tiers if interval not in SCHEDULABLE_BUCKETS)if unsupported:@@ -335,10 +339,17 @@ async def _apply_reconciliation(logger.debug("DAG not converted to cadence tiers yet, skipping reconcile", dag_id=dag_id)return# An empty tier set on a DAG that still has only legacy (non-tier) schedules means an unseeded- # conversion — protect it. Once tier schedules exist, empty desired is a deliberate wind-down- # (last target reverted/cleared/"never"), so let the teardown sweep the stale tiers instead of- # leaving them firing execute-dag on node_ids that no longer materialize.- if not desired_tiers and existing_ids and not any(is_tier_schedule_id(schedule_id) for schedule_id in existing_ids):+ # conversion — protect it, but only when there is anything to seed: a DAG with no schedulable+ # nodes gets its legacy schedule swept instead of firing no-op runs forever. Once tier+ # schedules exist, empty desired is a deliberate wind-down (last target reverted/cleared/+ # "never"), so let the teardown sweep the stale tiers instead of leaving them firing+ # execute-dag on node_ids that no longer materialize.+ if (+ not desired_tiers+ and has_schedulable_nodes+ and existing_ids+ and not any(is_tier_schedule_id(schedule_id) for schedule_id in existing_ids)+ ):logger.warning("Refusing to unschedule an unseeded DAG with only legacy schedules",dag_id=dag_id,diff --git a/products/data_modeling/backend/test/test_schedule_reconcile.py b/products/data_modeling/backend/test/test_schedule_reconcile.pyindex e31aca1feedb..367071864161 100644--- a/products/data_modeling/backend/test/test_schedule_reconcile.py+++ b/products/data_modeling/backend/test/test_schedule_reconcile.py@@ -186,6 +186,33 @@ class TestReconcileDagSchedules(BaseTest):create.assert_not_called()delete.assert_not_called()+ def test_sweeps_legacy_schedule_when_dag_has_no_schedulable_nodes(self):+ # a DAG holding only source tables has nothing to seed, so the unseeded-conversion+ # guard must not apply: its legacy schedule just fires no-op execute-dag runs forever+ dag = DAG.get_or_create_default(self.team)+ _table_node(self.team, dag, "events", {"origin": "posthog"})++ legacy_id = str(dag.id)++ async def fake_list_schedules(*_args, **_kwargs):+ async def gen():+ yield _listing(legacy_id)++ return gen()++ temporal = mock.Mock()+ temporal.list_schedules = fake_list_schedules++ with (+ mock.patch(f"{RECONCILE}.async_connect", new=mock.AsyncMock(return_value=temporal)),+ mock.patch(f"{RECONCILE}.a_create_schedule", new=mock.AsyncMock()) as create,+ mock.patch(f"{RECONCILE}.a_delete_schedule", new=mock.AsyncMock()) as delete,+ ):+ reconcile_dag_schedules(dag)++ create.assert_not_called()+ delete.assert_called_once_with(temporal, schedule_id=legacy_id)+def test_winds_down_tier_schedules_when_all_targets_cleared(self):# reverting/clearing the last target leaves empty desired tiers; once tier schedules exist# that is a deliberate wind-down, so the stale tier must be torn down rather than left