Repository navigation
fix(plan): pass plan snapshots and deployability index to audit-only stage - #6258
codewithsruthi wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…stage Signed-off-by: Sruthi <codewithsruthi@users.noreply.github.com>
32fd88a to
2d3e3a5
Compare
Description
Fixes #6256
Problem & Root Cause
PlanStagesBuilder.build()constructedAuditOnlyRunStagewith onlyaudit_only_snapshots, omittingall_snapshotsanddeployability_index, and could include non-representative devMETADATAsnapshots whose__devtable does not exist yet (whichBackfillStagecreates and audits right after).BuiltInPlanEvaluator.visit_audit_only_run_stage()built aSchedulerfrom only the audited snapshots, causing parent models referenced in audits to fall back to environment views — failing on newly added parents or silently auditing stale views after a partially failed prod plan, failing on dev breaking/preview parents and embedded parents, and losingstart_dateinheritance.Scheduler._run_or_audit()refreshed snapshot intervals and mutatedself.snapshots[s_id].remove_interval(...)in place on sharedSnapshotobjects held by subsequent stages (BackfillStage) andCachingStateSync, which could wipe intervals on audited incremental models whenAuditOnlyRunStageandBackfillStageran in the same plan. Additionally,Scheduler.run_merged_intervals()still computedsnapshots_to_create(and could emitCreateNode) whenaudit_only=True.Changes
sqlmesh/core/plan/stages.py:all_snapshots: t.Dict[str, Snapshot]anddeployability_index: DeployabilityIndextoAuditOnlyRunStageand populated them inPlanStagesBuilder.build().deployability_indexto_get_audit_only_snapshots()and excluded non-representative dev snapshots without existingdev_intervalssoAuditOnlyRunStagedoes not attempt to audit a not-yet-created__devtable beforeBackfillStage.sqlmesh/core/plan/evaluator.py:BuiltInPlanEvaluator.visit_audit_only_run_stage()to traverse upward fromstage.snapshotsthroughsnapshot.parents, shallow-copying only the audited snapshots and their upstream ancestors (includingintervals,dev_intervals, andpending_restatement_intervals) so state refreshes cannot mutate shared snapshots or refresh unrelated project snapshots, and forwardedselected_snapshots,deployability_index,ignore_cron, andcircuit_breakertoscheduler.audit(...).sqlmesh/core/scheduler.py:snapshotspassed to_audit_snapshot()duringaudit_only=Trueto{snapshot.name: snapshot}plussnapshot.parentspresent inself.snapshots(matchingScheduler.evaluate()so unrelated breaking/new sibling models in the same plan are not resolved to uncreated physical tables).snapshots_to_create = set()whenaudit_only=Trueinrun_merged_intervals()so audit-only runs never query physical objects for creation or scheduleCreateNode.remove_intervalsinScheduler.audit()tosnapshot.evaluatablesnapshots matchingselected_snapshots, preventingValueErroron unselecteddepends_on_pastsnapshots whenexecution_time < start, and guarded in-placeremove_intervalin_run_or_audit()withif not audit_only:.Test Plan
tests/core/test_plan_stages.py(AuditOnlyRunStageall_snapshots+deployability_indexfor dev and prod, and excluding non-representative dev snapshots withoutdev_intervalswhile including them once populated)tests/core/test_plan_evaluator.py(visit_audit_only_run_stageancestor-scoped snapshot copying, no shared mutation, argument forwarding, andPlanErroron audit failure)tests/core/test_scheduler.py(selected_snapshots,deployability_index, embedded parent, unselecteddepends_on_pastsafety, no in-memory interval mutation, noget_snapshots_to_createcall, sibling exclusion, and missing-parent tolerance)tests/core/integration/test_audits.py(faithful#6256repros with failedafter_promoteprod plan + pure audit-only follow-up for new/changed parents, dev breaking parent with/withoutselect_models, dev paused forward-only preview, embedded parent, external model,INCREMENTAL_BY_UNIQUE_KEYhistorical row preservation, uncreated sibling table safety, and non-representative devFULL/INCREMENTAL_BY_TIME_RANGEmodels)make py-style: Passed (ruff,ruff-format,mypy,valid migrations)make fast-test: Passed (3,134 passed, 0 failed across all fast/isolated/fork/registry/dialect suites)pytest tests/core/test_plan_stages.py tests/core/test_plan_evaluator.py tests/core/test_scheduler.py tests/core/integration/test_audits.py: Passed (66 passed)make doc-test: Passed (29 passed)Checklist
make py-styleand fixed any issuesmake fast-test)git commit -s) per the DCOSummary by CodeRabbit