@@ -310,26 +310,23 @@ def _load_external_models(
310
310
# external models with no explicit gateway defined form the base set
311
311
for model in external_models :
312
312
if model .gateway is None :
313
- < << << << HEAD
314
313
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
+ )
317
318
)
318
319
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
- >> >> >> > 80487e4 f (add mock executor ; fix loader ; adapt unit tests )
325
320
326
321
# however, if there is a gateway defined, gateway-specific models take precedence
327
322
if gateway :
328
323
for model in external_models :
329
324
if model .gateway == gateway :
330
325
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
+ )
333
330
)
334
331
models .update ({model .fqn : model })
335
332
@@ -416,8 +413,9 @@ def _track_file(self, path: Path) -> None:
416
413
"""Project file to track for modifications"""
417
414
self ._path_mtimes [path ] = path .stat ().st_mtime
418
415
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
+
421
419
422
420
class SqlMeshLoader (Loader ):
423
421
"""Loads macros and models for a context using the SQLMesh file formats"""
@@ -554,17 +552,18 @@ def _load_sql_models(
554
552
path = futures_to_paths [future ]
555
553
try :
556
554
_ , 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
566
565
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 )) )
568
567
569
568
if errors :
570
569
error_string = "\n " .join (errors )
@@ -620,7 +619,7 @@ def _load_python_models(
620
619
if model .enabled :
621
620
models [model .fqn ] = model
622
621
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 ) ))
624
623
625
624
finally :
626
625
model_registry ._dialect = None
0 commit comments