4444 list_of_fields_validator ,
4545 model_validator ,
4646 get_dialect ,
47+ validation_data ,
4748)
4849
4950if t .TYPE_CHECKING :
@@ -135,7 +136,7 @@ def _func_call_validator(cls, v: t.Any, field: t.Any) -> t.Any:
135136
136137 @field_validator ("tags" , mode = "before" )
137138 def _value_or_tuple_validator (cls , v : t .Any , info : ValidationInfo ) -> t .Any :
138- return ensure_list (cls ._validate_value_or_tuple (v , info . data ))
139+ return ensure_list (cls ._validate_value_or_tuple (v , validation_data ( info ) ))
139140
140141 @classmethod
141142 def _validate_value_or_tuple (
@@ -164,7 +165,7 @@ def _normalize(value: t.Any) -> t.Any:
164165 @field_validator ("table_format" , "storage_format" , mode = "before" )
165166 def _format_validator (cls , v : t .Any , info : ValidationInfo ) -> t .Optional [str ]:
166167 if isinstance (v , exp .Expr ) and not (isinstance (v , (exp .Literal , exp .Identifier ))):
167- return v .sql (info . data .get ("dialect" ))
168+ return v .sql (validation_data ( info ) .get ("dialect" ))
168169 return str_or_exp_to_str (v )
169170
170171 @field_validator ("dialect" , mode = "before" )
@@ -192,7 +193,7 @@ def _partition_and_cluster_validator(cls, v: t.Any, info: ValidationInfo) -> t.L
192193 if (
193194 isinstance (v , list )
194195 and all (isinstance (i , str ) for i in v )
195- and info .field_name == "partitioned_by_"
196+ and ( info .field_name or "" ) == "partitioned_by_"
196197 ):
197198 # this branch gets hit when we are deserializing from json because `partitioned_by` is stored as a List[str]
198199 # however, we should only invoke this if the list contains strings because this validator is also
@@ -205,7 +206,7 @@ def _partition_and_cluster_validator(cls, v: t.Any, info: ValidationInfo) -> t.L
205206 )
206207 v = parsed .this .expressions if isinstance (parsed .this , exp .Schema ) else v
207208
208- expressions = list_of_fields_validator (v , info . data )
209+ expressions = list_of_fields_validator (v , validation_data ( info ) )
209210
210211 for expression in expressions :
211212 num_cols = len (list (expression .find_all (exp .Column )))
@@ -228,7 +229,7 @@ def _columns_validator(
228229 cls , v : t .Any , info : ValidationInfo
229230 ) -> t .Optional [t .Dict [str , exp .DataType ]]:
230231 columns_to_types = {}
231- dialect = info . data .get ("dialect" )
232+ dialect = validation_data ( info ) .get ("dialect" )
232233
233234 if isinstance (v , exp .Schema ):
234235 for column in v .expressions :
@@ -280,7 +281,8 @@ def _columns_validator(
280281 def _column_descriptions_validator (
281282 cls , vs : t .Any , info : ValidationInfo
282283 ) -> t .Optional [t .Dict [str , str ]]:
283- dialect = info .data .get ("dialect" )
284+ data = validation_data (info )
285+ dialect = data .get ("dialect" )
284286
285287 if vs is None :
286288 return None
@@ -302,23 +304,23 @@ def _column_descriptions_validator(
302304 for k , v in raw_col_descriptions .items ()
303305 }
304306
305- columns_to_types = info . data .get ("columns_to_types_" )
307+ columns_to_types = data .get ("columns_to_types_" )
306308 if columns_to_types :
307309 from sqlmesh .core .console import get_console
308310
309311 console = get_console ()
310312 for column_name in list (col_descriptions ):
311313 if column_name not in columns_to_types :
312314 console .log_warning (
313- f"In model '{ info . data [ 'name' ] } ', a description is provided for column '{ column_name } ' but it is not a column in the model."
315+ f"In model '{ data . get ( 'name' , '<unknown>' ) } ', a description is provided for column '{ column_name } ' but it is not a column in the model."
314316 )
315317 del col_descriptions [column_name ]
316318
317319 return col_descriptions
318320
319321 @field_validator ("grains" , "references" , mode = "before" )
320322 def _refs_validator (cls , vs : t .Any , info : ValidationInfo ) -> t .List [exp .Expr ]:
321- dialect = info . data .get ("dialect" )
323+ dialect = validation_data ( info ) .get ("dialect" )
322324
323325 if isinstance (vs , exp .Paren ):
324326 vs = vs .unnest ()
0 commit comments