|
10 | 10 | from sqlglot import exp |
11 | 11 |
|
12 | 12 | from sqlmesh.core import constants as c |
13 | | -from sqlmesh.core.audit import Audit |
| 13 | +from sqlmesh.core.audit import BUILT_IN_AUDITS, Audit |
14 | 14 | from sqlmesh.core.model import ( |
15 | 15 | Model, |
16 | 16 | PythonModel, |
@@ -786,21 +786,26 @@ def _model_metadata_hash(model: Model, audits: t.Dict[str, Audit]) -> str: |
786 | 786 | ] |
787 | 787 |
|
788 | 788 | for audit_name, audit_args in sorted(model.audits, key=lambda a: a[0]): |
789 | | - if audit_name not in audits: |
790 | | - continue |
791 | | - |
792 | | - audit = audits[audit_name] |
793 | | - metadata.extend( |
794 | | - [ |
795 | | - audit.name, |
796 | | - audit.render_query(model, **t.cast(t.Dict[str, t.Any], audit_args)).sql( |
797 | | - identify=True, comments=True |
798 | | - ), |
799 | | - audit.dialect, |
800 | | - str(audit.skip), |
801 | | - str(audit.blocking), |
802 | | - ] |
803 | | - ) |
| 789 | + metadata.append(audit_name) |
| 790 | + |
| 791 | + if audit_name in BUILT_IN_AUDITS: |
| 792 | + for arg_name, arg_value in audit_args.items(): |
| 793 | + metadata.append(arg_name) |
| 794 | + metadata.append(arg_value.sql(identify=True, comments=True)) |
| 795 | + elif audit_name in audits: |
| 796 | + audit = audits[audit_name] |
| 797 | + metadata.extend( |
| 798 | + [ |
| 799 | + audit.render_query(model, **t.cast(t.Dict[str, t.Any], audit_args)).sql( |
| 800 | + identify=True, comments=True |
| 801 | + ), |
| 802 | + audit.dialect, |
| 803 | + str(audit.skip), |
| 804 | + str(audit.blocking), |
| 805 | + ] |
| 806 | + ) |
| 807 | + else: |
| 808 | + raise SQLMeshError(f"Unexpected audit name '{audit_name}'.") |
804 | 809 |
|
805 | 810 | # Add comments from the model query. |
806 | 811 | for e, _, _ in model.render_query().walk(): |
|
0 commit comments