@@ -2173,24 +2173,18 @@ def load_sql_based_model(
2173
2173
** meta_fields ,
2174
2174
)
2175
2175
2176
- if query_or_seed_insert is not None and (
2177
- isinstance (query_or_seed_insert , (exp .Query , d .JinjaQuery ))
2178
- or (
2179
- # Macro functions are allowed in place of model queries only when there are no
2180
- # other statements in the model definition, otherwise they would be ambiguous
2181
- isinstance (query_or_seed_insert , d .MacroFunc )
2182
- and (query_or_seed_insert .this .name .lower () == "union" or len (expressions ) == 2 )
2183
- )
2184
- ):
2176
+ kind = common_kwargs .pop ("kind" , ModelMeta .all_field_infos ()["kind" ].default )
2177
+
2178
+ if kind .name != ModelKindName .SEED :
2185
2179
return create_sql_model (
2186
2180
name ,
2187
2181
query_or_seed_insert ,
2182
+ kind = kind ,
2188
2183
time_column_format = time_column_format ,
2189
2184
** common_kwargs ,
2190
2185
)
2191
- seed_properties = {
2192
- p .name .lower (): p .args .get ("value" ) for p in common_kwargs .pop ("kind" ).expressions
2193
- }
2186
+
2187
+ seed_properties = {p .name .lower (): p .args .get ("value" ) for p in kind .expressions }
2194
2188
return create_seed_model (
2195
2189
name ,
2196
2190
SeedKind (** seed_properties ),
@@ -2200,7 +2194,7 @@ def load_sql_based_model(
2200
2194
2201
2195
def create_sql_model (
2202
2196
name : TableName ,
2203
- query : exp .Expression ,
2197
+ query : t . Optional [ exp .Expression ] ,
2204
2198
** kwargs : t .Any ,
2205
2199
) -> Model :
2206
2200
"""Creates a SQL model.
@@ -2215,6 +2209,7 @@ def create_sql_model(
2215
2209
"A query is required and must be a SELECT statement, a UNION statement, or a JINJA_QUERY block" ,
2216
2210
kwargs .get ("path" ),
2217
2211
)
2212
+ assert isinstance (query , (exp .Query , d .JinjaQuery , d .MacroFunc ))
2218
2213
2219
2214
return _create_model (SqlModel , name , query = query , ** kwargs )
2220
2215
0 commit comments