@@ -1638,6 +1638,8 @@ def is_seed(self) -> bool:
16381638 def seed_path (self ) -> Path :
16391639 seed_path = Path (self .kind .path )
16401640 if not seed_path .is_absolute ():
1641+ if self ._path is None :
1642+ raise SQLMeshError (f"Seed model '{ self .name } ' has no path" )
16411643 return self ._path .parent / seed_path
16421644 return seed_path
16431645
@@ -2003,7 +2005,7 @@ def load_sql_based_model(
20032005 expressions : t .List [exp .Expression ],
20042006 * ,
20052007 defaults : t .Optional [t .Dict [str , t .Any ]] = None ,
2006- path : Path = Path () ,
2008+ path : t . Optional [ Path ] = None ,
20072009 module_path : Path = Path (),
20082010 time_column_format : str = c .DEFAULT_TIME_COLUMN_FORMAT ,
20092011 macros : t .Optional [MacroRegistry ] = None ,
@@ -2154,6 +2156,8 @@ def load_sql_based_model(
21542156 # The name of the model will be inferred from its path relative to `models/`, if it's not explicitly specified
21552157 name = meta_fields .pop ("name" , "" )
21562158 if not name and infer_names :
2159+ if path is None :
2160+ raise ValueError ("Model must have a name" , path )
21572161 name = get_model_name (path )
21582162
21592163 if not name :
@@ -2232,7 +2236,7 @@ def create_seed_model(
22322236 name : TableName ,
22332237 seed_kind : SeedKind ,
22342238 * ,
2235- path : Path = Path () ,
2239+ path : t . Optional [ Path ] = None ,
22362240 module_path : Path = Path (),
22372241 ** kwargs : t .Any ,
22382242) -> Model :
@@ -2251,7 +2255,12 @@ def create_seed_model(
22512255 seed_path = module_path .joinpath (* subdirs )
22522256 seed_kind .path = str (seed_path )
22532257 elif not seed_path .is_absolute ():
2254- seed_path = path / seed_path if path .is_dir () else path .parent / seed_path
2258+ if path is None :
2259+ seed_path = seed_path
2260+ elif path .is_dir ():
2261+ seed_path = path / seed_path
2262+ else :
2263+ seed_path = path .parent / seed_path
22552264
22562265 seed = create_seed (seed_path )
22572266
@@ -2386,7 +2395,7 @@ def _create_model(
23862395 name : TableName ,
23872396 * ,
23882397 defaults : t .Optional [t .Dict [str , t .Any ]] = None ,
2389- path : Path = Path () ,
2398+ path : t . Optional [ Path ] = None ,
23902399 time_column_format : str = c .DEFAULT_TIME_COLUMN_FORMAT ,
23912400 jinja_macros : t .Optional [JinjaMacroRegistry ] = None ,
23922401 jinja_macro_references : t .Optional [t .Set [MacroReference ]] = None ,
@@ -2571,7 +2580,7 @@ def _create_model(
25712580
25722581def _split_sql_model_statements (
25732582 expressions : t .List [exp .Expression ],
2574- path : Path ,
2583+ path : t . Optional [ Path ] ,
25752584 dialect : t .Optional [str ] = None ,
25762585) -> t .Tuple [
25772586 t .Optional [exp .Expression ],
@@ -2692,7 +2701,7 @@ def _refs_to_sql(values: t.Any) -> exp.Expression:
26922701def render_meta_fields (
26932702 fields : t .Dict [str , t .Any ],
26942703 module_path : Path ,
2695- path : Path ,
2704+ path : t . Optional [ Path ] ,
26962705 jinja_macros : t .Optional [JinjaMacroRegistry ],
26972706 macros : t .Optional [MacroRegistry ],
26982707 dialect : DialectType ,
@@ -2776,7 +2785,7 @@ def render_field_value(value: t.Any) -> t.Any:
27762785def render_model_defaults (
27772786 defaults : t .Dict [str , t .Any ],
27782787 module_path : Path ,
2779- path : Path ,
2788+ path : t . Optional [ Path ] ,
27802789 jinja_macros : t .Optional [JinjaMacroRegistry ],
27812790 macros : t .Optional [MacroRegistry ],
27822791 dialect : DialectType ,
@@ -2826,7 +2835,7 @@ def parse_defaults_properties(
28262835def render_expression (
28272836 expression : exp .Expression ,
28282837 module_path : Path ,
2829- path : Path ,
2838+ path : t . Optional [ Path ] ,
28302839 jinja_macros : t .Optional [JinjaMacroRegistry ] = None ,
28312840 macros : t .Optional [MacroRegistry ] = None ,
28322841 dialect : DialectType = None ,
0 commit comments