@@ -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- >> >> >> > 80487e4 f (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
422420class 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
0 commit comments