Skip to content

Commit 0f192c9

Browse files
Fix!: Include custom audit args in the metadata hash (#5758)
Signed-off-by: Themis Valtinos <73662635+themisvaltinos@users.noreply.github.com>
1 parent 41a9d29 commit 0f192c9

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

sqlmesh/core/model/definition.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,11 +1158,7 @@ def _audit_metadata_hash_values(self) -> t.List[str]:
11581158

11591159
for audit_name, audit_args in sorted(self.audits, key=lambda a: a[0]):
11601160
metadata.append(audit_name)
1161-
if audit_name in BUILT_IN_AUDITS:
1162-
for arg_name, arg_value in audit_args.items():
1163-
metadata.append(arg_name)
1164-
metadata.append(gen(arg_value))
1165-
else:
1161+
if audit_name not in BUILT_IN_AUDITS:
11661162
audit = self.audit_definitions[audit_name]
11671163
metadata.extend(
11681164
[
@@ -1172,6 +1168,9 @@ def _audit_metadata_hash_values(self) -> t.List[str]:
11721168
str(audit.blocking),
11731169
]
11741170
)
1171+
for arg_name, arg_value in audit_args.items():
1172+
metadata.append(arg_name)
1173+
metadata.append(gen(arg_value))
11751174

11761175
return metadata
11771176

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Include custom audit args in the model fingerprint."""
2+
3+
4+
def migrate_schemas(engine_adapter, schema, **kwargs): # type: ignore
5+
pass
6+
7+
8+
def migrate_rows(engine_adapter, schema, **kwargs): # type: ignore
9+
pass

tests/core/test_model.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,37 @@ def test_audits():
16651665
assert model.tags == ["foo"]
16661666

16671667

1668+
def test_custom_audit_arg_changes_affect_fingerprint():
1669+
def make_model(min_val: int) -> t.Any:
1670+
expressions = d.parse(
1671+
f"""
1672+
MODEL (
1673+
name db.model,
1674+
audits (check_count(min := {min_val}))
1675+
);
1676+
SELECT 1 AS id;
1677+
"""
1678+
)
1679+
audit_definitions = {
1680+
"check_count": load_audit(
1681+
d.parse(
1682+
"AUDIT (name check_count); SELECT * FROM @this_model HAVING COUNT(*) < @min"
1683+
),
1684+
dialect="duckdb",
1685+
)
1686+
}
1687+
return load_sql_based_model(
1688+
expressions,
1689+
path=Path("./examples/sushi/models/test_model.sql"),
1690+
audit_definitions=audit_definitions,
1691+
)
1692+
1693+
model_a = make_model(33111)
1694+
model_b = make_model(5142)
1695+
1696+
assert model_a.audit_metadata_hash() != model_b.audit_metadata_hash()
1697+
1698+
16681699
def test_enable_audits_from_model_defaults():
16691700
expressions = d.parse(
16701701
"""

0 commit comments

Comments
 (0)