Skip to content

Commit 9d7c385

Browse files
authored
Fix: plan physical tables progress bar (#3578)
1 parent c62d668 commit 9d7c385

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

sqlmesh/core/plan/evaluator.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,6 @@ def _push(
223223
for s in snapshots.values()
224224
if s.is_model and not s.is_symbolic and plan.is_selected_for_backfill(s.name)
225225
]
226-
snapshots_to_create_count = len(snapshots_to_create)
227-
228-
if snapshots_to_create_count > 0:
229-
self.console.start_creation_progress(
230-
snapshots_to_create_count, plan.environment, self.default_catalog
231-
)
232226

233227
completed = False
234228
try:
@@ -237,6 +231,9 @@ def _push(
237231
snapshots,
238232
allow_destructive_snapshots=plan.allow_destructive_models,
239233
deployability_index=deployability_index,
234+
on_start=lambda x: self.console.start_creation_progress(
235+
x, plan.environment, self.default_catalog
236+
),
240237
on_complete=self.console.update_creation_progress,
241238
)
242239
completed = True

sqlmesh/core/snapshot/evaluator.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def create(
261261
target_snapshots: t.Iterable[Snapshot],
262262
snapshots: t.Dict[SnapshotId, Snapshot],
263263
deployability_index: t.Optional[DeployabilityIndex] = None,
264+
on_start: t.Optional[t.Callable] = None,
264265
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
265266
allow_destructive_snapshots: t.Set[str] = set(),
266267
) -> None:
@@ -270,6 +271,7 @@ def create(
270271
target_snapshots: Target snapshots.
271272
snapshots: Mapping of snapshot ID to snapshot.
272273
deployability_index: Determines snapshots that are deployable in the context of this creation.
274+
on_start: A callback to initialize the snapshot creation progress bar.
273275
on_complete: A callback to call on each successfully created snapshot.
274276
allow_destructive_snapshots: Set of snapshots that are allowed to have destructive schema changes.
275277
"""
@@ -326,11 +328,11 @@ def _get_data_objects(schema: exp.Table, gateway: t.Optional[str] = None) -> t.S
326328
table_deployability[table_name]
327329
)
328330
target_deployability_flags[snapshot.name].sort()
329-
elif on_complete:
330-
on_complete(snapshot)
331331

332332
if not snapshots_to_create:
333333
return
334+
if on_start:
335+
on_start(len(snapshots_to_create))
334336
self._create_schemas(tables_by_schema, gateway_by_schema)
335337
self._create_snapshots(
336338
snapshots_to_create,
@@ -350,7 +352,7 @@ def _create_snapshots(
350352
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]],
351353
allow_destructive_snapshots: t.Set[str],
352354
) -> None:
353-
"""Internal method to create tables in parrallel."""
355+
"""Internal method to create tables in parallel."""
354356
with self.concurrent_context():
355357
concurrent_apply_to_snapshots(
356358
snapshots_to_create,

tests/cli/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ def test_plan_restate_model(runner, tmp_path):
220220
assert_duckdb_test(result)
221221
assert "No changes to plan: project files match the `prod` environment" in result.output
222222
assert "sqlmesh_example.full_model evaluated in" in result.output
223-
assert_backfill_success(result)
223+
assert_model_batches_executed(result)
224+
assert_target_env_updated(result)
224225

225226

226227
@pytest.mark.parametrize("flag", ["--skip-backfill", "--dry-run"])
@@ -348,7 +349,6 @@ def test_plan_dev_create_from_virtual(runner, tmp_path):
348349
)
349350
assert result.exit_code == 0
350351
assert_new_env(result, "dev2", "dev", initialize=False)
351-
assert_model_versions_created(result)
352352
assert_target_env_updated(result)
353353
assert_virtual_update(result)
354354

0 commit comments

Comments
 (0)