Skip to content

Commit 143d9bb

Browse files
rebase; cleanup code
1 parent b8b24ea commit 143d9bb

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ engine-up: engine-clickhouse-up engine-mssql-up engine-mysql-up engine-postgres-
6464
engine-down: engine-clickhouse-down engine-mssql-down engine-mysql-down engine-postgres-down engine-spark-down engine-trino-down
6565

6666
fast-test:
67-
pytest -n auto -m "fast and not cicdonly" && pytest -m "isolated"
67+
pytest -n auto -m "fast and not cicdonly" && pytest -m "isolated" && pytest -m "isolated2"
6868

6969
slow-test:
7070
pytest -n auto -m "(fast or slow) and not cicdonly" && pytest -m "isolated"

sqlmesh/core/loader.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,23 @@ def _load_external_models(
310310
# external models with no explicit gateway defined form the base set
311311
for model in external_models:
312312
if model.gateway is None:
313-
<<<<<<< HEAD
314313
if model.fqn in models:
315-
self._raise_failed_to_load_model_error(
316-
path, f"Duplicate external model name: '{model.name}'."
314+
raise ConfigError(
315+
self._failed_to_load_model_error(
316+
path, f"Duplicate external model name: '{model.name}'."
317+
)
317318
)
318319
models[model.fqn] = model
319-
=======
320-
try:
321-
models[model.fqn] = model
322-
except Exception as ex:
323-
raise ConfigError(f"Failed to add model: {model.fqn}\n\n{ex}")
324-
>>>>>>> 80487e4f (add mock executor; fix loader; adapt unit tests)
325320

326321
# however, if there is a gateway defined, gateway-specific models take precedence
327322
if gateway:
328323
for model in external_models:
329324
if model.gateway == gateway:
330325
if model.fqn in models and models[model.fqn].gateway == gateway:
331-
self._raise_failed_to_load_model_error(
332-
path, f"Duplicate external model name: '{model.name}'."
326+
raise ConfigError(
327+
self._failed_to_load_model_error(
328+
path, f"Duplicate external model name: '{model.name}'."
329+
)
333330
)
334331
models.update({model.fqn: model})
335332

@@ -416,8 +413,9 @@ def _track_file(self, path: Path) -> None:
416413
"""Project file to track for modifications"""
417414
self._path_mtimes[path] = path.stat().st_mtime
418415

419-
def _raise_failed_to_load_model_error(self, path: Path, message: str) -> None:
420-
raise ConfigError(f"Failed to load model definition at '{path}'.\n{message}")
416+
def _failed_to_load_model_error(self, path: Path, message: str) -> str:
417+
return f"Failed to load model definition at '{path}'.\n{message}"
418+
421419

422420
class SqlMeshLoader(Loader):
423421
"""Loads macros and models for a context using the SQLMesh file formats"""
@@ -554,17 +552,18 @@ def _load_sql_models(
554552
path = futures_to_paths[future]
555553
try:
556554
_, loaded = future.result()
557-
if loaded:
558-
for model in loaded:
559-
if model.enabled:
560-
model._path = path
561-
models[model.fqn] = model
562-
else:
563-
for model in cache.get(path):
564-
if model.enabled:
565-
models[model.fqn] = model
555+
for model in loaded or cache.get(path):
556+
if model.fqn in models:
557+
errors.append(
558+
self._failed_to_load_model_error(
559+
path, f"Duplicate SQL model name: '{model.name}'."
560+
)
561+
)
562+
elif model.enabled:
563+
model._path = path
564+
models[model.fqn] = model
566565
except Exception as ex:
567-
errors.append(f"Failed to load model definition at '{path}'.\n\n{ex}")
566+
errors.append(self._failed_to_load_model_error(path, str(ex)))
568567

569568
if errors:
570569
error_string = "\n".join(errors)
@@ -620,7 +619,7 @@ def _load_python_models(
620619
if model.enabled:
621620
models[model.fqn] = model
622621
except Exception as ex:
623-
self._raise_failed_to_load_model_error(path, str(ex))
622+
raise ConfigError(self._failed_to_load_model_error(path, str(ex)))
624623

625624
finally:
626625
model_registry._dialect = None

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def validate(
183183

184184

185185
def pytest_collection_modifyitems(items, *args, **kwargs):
186-
test_type_markers = {"fast", "slow", "docker", "remote", "isolated"}
186+
test_type_markers = {"fast", "slow", "docker", "remote", "isolated", "isolated2"}
187187
for item in items:
188188
for marker in item.iter_markers():
189189
if marker.name in test_type_markers:

tests/core/test_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def duplicate_model_path(fpath):
115115
Context(paths=tmp_path, config=config)
116116

117117

118-
@pytest.mark.isolated
118+
@pytest.mark.isolated2
119119
def test_duplicate_python_model_names_raise_error(tmp_path: Path) -> None:
120120
"""Test python models with duplicate model names raises ConfigError if the functions are not identical."""
121121
init_example_project(tmp_path, dialect="duckdb")

0 commit comments

Comments
 (0)