Skip to content

Commit 076b1dc

Browse files
committed
Add partial multi-repo format test and doc caveat
Final review follow-ups: cover format on one repo of a multi-repo project whose upstream models live only in prod state, warn in the load_state docstring that plan/apply in multi-repo setups need it, and clarify why the CLI gate sits outside the single-path block. Signed-off-by: Joe Hartshorn <8881940+j-hartshorn@users.noreply.github.com>
1 parent c12af30 commit 076b1dc

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

sqlmesh/cli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def cli(
116116
configure_console(ignore_warnings=ignore_warnings)
117117

118118
load = True
119-
# Outside the single-path block: applies regardless of --paths count.
119+
# Local-only gating must hold for any number of --paths, so it stays outside the block below.
120120
load_state = ctx.invoked_subcommand not in LOCAL_ONLY_COMMANDS
121121

122122
if len(paths) == 1:

sqlmesh/core/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ class GenericContext(BaseContext, t.Generic[C]):
364364
concurrent_tasks: The maximum number of tasks that can use the connection concurrently.
365365
load: Whether or not to automatically load all models and macros (default True).
366366
load_state: Whether to merge remote state into the local project during load (default True).
367+
Only intended for local-only operations like format; plan/apply in multi-repo projects
368+
require it to see models owned by other projects.
367369
console: The rich instance used for printing out CLI command results.
368370
users: A list of users to make known to SQLMesh.
369371
"""

tests/cli/test_cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,16 @@ def test_format_runs_without_state(runner: CliRunner, tmp_path: Path, mocker):
22712271
mock.assert_not_called()
22722272

22732273

2274+
def test_format_runs_without_state_multi_repo_partial(runner: CliRunner, copy_to_temp_path, mocker):
2275+
"""Format one repo of a multi-repo project whose upstream models live only in prod state."""
2276+
repo_2 = copy_to_temp_path("examples/multi")[0] / "repo_2"
2277+
mock = _patch_state_access(mocker)
2278+
2279+
result = runner.invoke(cli, ["--gateway", "memory", "--paths", str(repo_2), "format"])
2280+
assert result.exit_code == 0, f"Format failed: {result.output}\nException: {result.exception}"
2281+
mock.assert_not_called()
2282+
2283+
22742284
def test_lint_still_loads_state(runner: CliRunner, tmp_path: Path, mocker):
22752285
"""Guard that `lint` explicitly passes `load_state=True` and still reaches state sync."""
22762286
mock = _setup_local_only_project(tmp_path, mocker)

0 commit comments

Comments
 (0)