Skip to content

Commit b3b1d52

Browse files
authored
Fix: Improve error messages around concurrent plan application (#4490)
1 parent 6767e35 commit b3b1d52

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

sqlmesh/core/state_sync/db/environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ def finalize(self, environment: Environment) -> None:
152152
stored_plan_id = stored_plan_id_row[0]
153153
if stored_plan_id != environment.plan_id:
154154
raise SQLMeshError(
155-
f"Plan '{environment.plan_id}' is no longer valid for the target environment '{environment.name}'. "
156-
f"Stored plan ID: '{stored_plan_id}'. Please recreate the plan and try again"
155+
f"Another plan ({stored_plan_id}) was applied to the target environment '{environment.name}' while your current plan "
156+
f"({environment.plan_id}) was still in progress, interrupting it. Please re-apply your plan to resolve this error."
157157
)
158158

159159
environment.finalized_ts = now_timestamp()

sqlmesh/core/state_sync/db/facade.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,8 @@ def promote(
205205
if not existing_environment.expired:
206206
if environment.previous_plan_id != existing_environment.plan_id:
207207
raise ConflictingPlanError(
208-
f"Plan '{environment.plan_id}' is no longer valid for the target environment '{environment.name}'. "
209-
f"Expected previous plan ID: '{environment.previous_plan_id}', actual previous plan ID: '{existing_environment.plan_id}'. "
210-
"Please recreate the plan and try again"
208+
f"Another plan ({existing_environment.plan_id}) was applied to the target environment '{environment.name}' while your current plan "
209+
f"({environment.plan_id}) was still in progress, interrupting it. Please re-apply your plan to resolve this error."
211210
)
212211
if no_gaps_snapshot_names != set():
213212
snapshots = self.get_snapshots(environment.snapshots).values()
@@ -614,7 +613,8 @@ def _ensure_no_gaps(
614613

615614
if missing_intervals:
616615
raise SQLMeshError(
617-
f"Detected gaps in snapshot {target_snapshot.snapshot_id}: {missing_intervals}"
616+
f"Detected missing intervals for model {target_snapshot.name}, interrupting your current plan. "
617+
"Please re-apply your plan to resolve this error."
618618
)
619619

620620
@contextlib.contextmanager

tests/core/state_sync/test_state_sync.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,9 @@ def test_promote_snapshots_parent_plan_id_mismatch(
860860

861861
with pytest.raises(
862862
SQLMeshError,
863-
match=r".*is no longer valid.*",
863+
match=re.escape(
864+
"Another plan (new_plan_id) was applied to the target environment 'prod' while your current plan (stale_new_plan_id) was still in progress, interrupting it. Please re-apply your plan to resolve this error."
865+
),
864866
):
865867
state_sync.promote(stale_new_environment)
866868

@@ -947,7 +949,7 @@ def test_promote_snapshots_no_gaps(state_sync: EngineAdapterStateSync, make_snap
947949
state_sync.add_interval(new_snapshot_missing_interval, "2022-01-01", "2022-01-02")
948950
with pytest.raises(
949951
SQLMeshError,
950-
match=r"Detected gaps in snapshot.*",
952+
match=r'Detected missing intervals for model "a", interrupting your current plan. Please re-apply your plan to resolve this error.',
951953
):
952954
promote_snapshots(state_sync, [new_snapshot_missing_interval], "prod", no_gaps=True)
953955

@@ -1023,7 +1025,9 @@ def test_finalize(state_sync: EngineAdapterStateSync, make_snapshot: t.Callable)
10231025
env.plan_id = "different_plan_id"
10241026
with pytest.raises(
10251027
SQLMeshError,
1026-
match=r"Plan 'different_plan_id' is no longer valid for the target environment 'prod'.*",
1028+
match=re.escape(
1029+
"Another plan (test_plan_id) was applied to the target environment 'prod' while your current plan (different_plan_id) was still in progress, interrupting it. Please re-apply your plan to resolve this error."
1030+
),
10271031
):
10281032
state_sync.finalize(env)
10291033

@@ -1057,7 +1061,7 @@ def test_start_date_gap(state_sync: EngineAdapterStateSync, make_snapshot: t.Cal
10571061
state_sync.add_interval(snapshot, "2022-01-03", "2022-01-04")
10581062
with pytest.raises(
10591063
SQLMeshError,
1060-
match=r"Detected gaps in snapshot.*",
1064+
match=r'Detected missing intervals for model "a", interrupting your current plan. Please re-apply your plan to resolve this error.',
10611065
):
10621066
promote_snapshots(state_sync, [snapshot], "prod", no_gaps=True)
10631067

0 commit comments

Comments
 (0)