Skip to content

Commit 87f3da4

Browse files
committed
Fix: Improve error messages around concurrent plan application
1 parent 8bbcd85 commit 87f3da4

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
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 the current plan "
156+
f"({environment.plan_id}) was still in progress. 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: 2 additions & 3 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 the current plan "
209+
f"({environment.plan_id}) was still in progress. 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()

tests/core/state_sync/test_state_sync.py

Lines changed: 6 additions & 2 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 the current plan (stale_new_plan_id) was still in progress. Please re-apply your plan to resolve this error."
865+
),
864866
):
865867
state_sync.promote(stale_new_environment)
866868

@@ -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 the current plan (different_plan_id) was still in progress. Please re-apply your plan to resolve this error."
1030+
),
10271031
):
10281032
state_sync.finalize(env)
10291033

0 commit comments

Comments
 (0)