3636 JinjaMacroRegistry ,
3737 extract_macro_references_and_variables ,
3838)
39+ from sqlmesh .utils .pydantic import field_validator , field_validator_v1_args
3940from sqlmesh .utils .metaprogramming import (
4041 Executable ,
4142 build_env ,
@@ -637,6 +638,10 @@ def disable_restatement(self) -> bool:
637638 def wap_supported (self ) -> bool :
638639 return self .kind .is_materialized and (self .storage_format or "" ).lower () == "iceberg"
639640
641+ @property
642+ def inline_audits (self ) -> t .Dict [str , ModelAudit ]:
643+ return {}
644+
640645 def validate_definition (self ) -> None :
641646 """Validates the model's definition.
642647
@@ -834,11 +839,30 @@ class _SqlBasedModel(_Model):
834839 post_statements_ : t .Optional [t .List [exp .Expression ]] = Field (
835840 default = None , alias = "post_statements"
836841 )
842+ inline_audits_ : t .Dict [str , t .Any ] = Field (default = {}, alias = "inline_audits" )
837843
838844 __statement_renderers : t .Dict [int , ExpressionRenderer ] = {}
839845
840846 _expression_validator = expression_validator
841847
848+ @field_validator ("inline_audits_" , mode = "before" )
849+ @field_validator_v1_args
850+ def _inline_audits_validator (cls , v : t .Any , values : t .Dict [str , t .Any ]) -> t .Any :
851+ if not isinstance (v , dict ):
852+ return {}
853+
854+ from sqlmesh .core .audit import ModelAudit
855+
856+ inline_audits = {}
857+
858+ for name , audit in v .items ():
859+ if isinstance (audit , ModelAudit ):
860+ inline_audits [name ] = audit
861+ elif isinstance (audit , dict ):
862+ inline_audits [name ] = ModelAudit .parse_obj (audit )
863+
864+ return inline_audits
865+
842866 def render_pre_statements (
843867 self ,
844868 * ,
@@ -900,6 +924,10 @@ def macro_definitions(self) -> t.List[d.MacroDef]:
900924 """All macro definitions from the list of expressions."""
901925 return [s for s in self .pre_statements + self .post_statements if isinstance (s , d .MacroDef )]
902926
927+ @property
928+ def inline_audits (self ) -> t .Dict [str , ModelAudit ]:
929+ return self .inline_audits_
930+
903931 def _render_statements (
904932 self ,
905933 statements : t .Iterable [exp .Expression ],
@@ -1859,7 +1887,6 @@ def _create_model(
18591887 depends_on : t .Optional [t .Set [str ]] = None ,
18601888 dialect : t .Optional [str ] = None ,
18611889 physical_schema_override : t .Optional [t .Dict [str , str ]] = None ,
1862- inline_audits : t .Optional [t .Dict [str , ModelAudit ]] = None ,
18631890 ** kwargs : t .Any ,
18641891) -> Model :
18651892 _validate_model_fields (klass , {"name" , * kwargs } - {"grain" , "table_properties" }, path )
@@ -1880,7 +1907,6 @@ def _create_model(
18801907 try :
18811908 model = klass (
18821909 name = name ,
1883- inline_audits = inline_audits ,
18841910 ** {
18851911 ** (defaults or {}),
18861912 "jinja_macros" : jinja_macros or JinjaMacroRegistry (),
0 commit comments