Skip to content

Commit e4b4867

Browse files
authored
fix(cli): coerce plan --min-intervals to int (#5919)
Signed-off-by: jthurlburt <jthurlburt818@gmail.com>
1 parent 61082a6 commit e4b4867

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

sqlmesh/cli/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ def diff(ctx: click.Context, environment: t.Optional[str] = None) -> None:
553553
)
554554
@click.option(
555555
"--min-intervals",
556+
type=int,
556557
default=None,
557558
help="For every model, ensure at least this many intervals are covered by a missing intervals check regardless of the plan start date",
558559
)

tests/cli/test_cli.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,44 @@ def test_plan_skip_backfill(runner, tmp_path, flag):
263263
assert "Model batches executed" not in result.output
264264

265265

266+
def test_plan_min_intervals(runner, tmp_path):
267+
create_example_project(tmp_path)
268+
269+
# build prod so the dev plan below has a baseline to diff against
270+
runner.invoke(
271+
cli,
272+
["--log-file-dir", tmp_path, "--paths", tmp_path, "plan", "--no-prompts", "--auto-apply"],
273+
)
274+
update_incremental_model(tmp_path)
275+
276+
# --min-intervals must be coerced to int; otherwise the string reaches
277+
# range() in _calculate_start_override_per_model and raises TypeError
278+
result = runner.invoke(
279+
cli,
280+
[
281+
"--log-file-dir",
282+
tmp_path,
283+
"--paths",
284+
tmp_path,
285+
"plan",
286+
"dev",
287+
"--no-prompts",
288+
"--auto-apply",
289+
"--min-intervals",
290+
"1",
291+
],
292+
)
293+
assert result.exit_code == 0, result.output
294+
295+
# a non-integer value is rejected by click, not surfaced as a traceback
296+
result = runner.invoke(
297+
cli,
298+
["--log-file-dir", tmp_path, "--paths", tmp_path, "plan", "dev", "--min-intervals", "abc"],
299+
)
300+
assert result.exit_code == 2
301+
assert "is not a valid integer" in result.output
302+
303+
266304
def test_plan_auto_apply(runner, tmp_path):
267305
create_example_project(tmp_path)
268306

0 commit comments

Comments
 (0)