Skip to content

Commit 79972f3

Browse files
author
cookieark
committed
fix: reload after the missing-model check fails in scoped test runs
The missing-model check now runs inside the same reset as the deferred validation, so a retry after the model is added reloads the project instead of skipping the check. Signed-off-by: cookieark <aishwary.kantode@gmail.com>
1 parent b63a1c2 commit 79972f3

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎sqlmesh/core/context.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,12 +2487,11 @@ def test(
24872487
tests_skipped = 0
24882488

24892489
if target_fqns is not None:
2490-
scoped_model_fqns = self._scoped_test_model_fqns(test_meta)
24912490
try:
2492-
self._update_model_schemas_and_validate(scoped_model_fqns)
2491+
self._update_model_schemas_and_validate(self._scoped_test_model_fqns(test_meta))
24932492
except Exception:
2494-
# Validation was deferred from the load above, so the load didn't complete.
2495-
# Otherwise, a retry after the file is fixed would reuse the invalid model.
2493+
# These checks were deferred from the load above, so the load didn't complete.
2494+
# Otherwise, a retry after the project is fixed would reuse the stale models.
24962495
self._loaded = False
24972496
raise
24982497

‎tests/core/test_test.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4084,3 +4084,33 @@ def test_use_project_index_reloads_after_failed_validation(
40844084
assert result.wasSuccessful(), result.failures + result.errors
40854085
assert result.testsRun == 1
40864086
assert not context.get_model("demo.a", raise_if_missing=True).partitioned_by
4087+
4088+
4089+
def test_use_project_index_reloads_after_missing_model_error(
4090+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
4091+
) -> None:
4092+
"""Adding the missing model and retrying on the same context must run the test."""
4093+
create_indexed_test_project(tmp_path)
4094+
(tmp_path / "tests" / "test_missing.yaml").write_text(
4095+
"""test_missing:
4096+
model: demo.nope
4097+
outputs:
4098+
query:
4099+
rows:
4100+
- id: 1
4101+
""",
4102+
encoding="utf-8",
4103+
)
4104+
monkeypatch.chdir(tmp_path)
4105+
4106+
context = Context(paths=tmp_path, load=False)
4107+
with pytest.raises(SQLMeshError, match="was not found"):
4108+
context.test(tests=["tests/test_missing.yaml"], use_project_index=True)
4109+
4110+
(tmp_path / "models" / "nope.sql").write_text(
4111+
"MODEL(name demo.nope, kind FULL); SELECT 1 AS id", encoding="utf-8"
4112+
)
4113+
result = context.test(tests=["tests/test_missing.yaml"], use_project_index=True)
4114+
4115+
assert result.wasSuccessful(), result.failures + result.errors
4116+
assert result.testsRun == 1

0 commit comments

Comments
 (0)