Skip to content

Commit 8d8a691

Browse files
authored
Fix: always warn when an audit has failed (#3255)
1 parent 50da27c commit 8d8a691

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,15 +859,15 @@ def _audit(
859859
select("COUNT(*)").from_(query.subquery("audit")),
860860
quote_identifiers=True,
861861
) # type: ignore
862-
if count and raise_exception:
862+
if count:
863863
audit_error = AuditError(
864864
audit_name=audit.name,
865865
model=snapshot.model_or_none,
866866
count=count,
867867
query=query,
868868
adapter_dialect=self.adapter.dialect,
869869
)
870-
if blocking:
870+
if raise_exception and blocking:
871871
raise audit_error
872872
else:
873873
logger.warning(f"{audit_error}\nAudit is warn only so proceeding with execution.")

tests/core/test_context.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,19 @@ def test_override_builtin_audit_blocking_mode():
361361
)
362362
)
363363

364-
plan = context.plan(auto_apply=True, no_prompts=True)
365-
new_snapshot = next(iter(plan.context_diff.new_snapshots.values()))
364+
logger = logging.getLogger("sqlmesh.core.snapshot.evaluator")
365+
with patch.object(logger, "warning") as mock_logger:
366+
plan = context.plan(auto_apply=True, no_prompts=True)
367+
new_snapshot = next(iter(plan.context_diff.new_snapshots.values()))
368+
369+
assert mock_logger.mock_calls == [
370+
call(
371+
"Audit 'not_null' for model 'db.x' failed.\n"
372+
"Got 1 results, expected 0.\n"
373+
'SELECT * FROM (SELECT * FROM "sqlmesh__db"."db__x__829001280" AS "db__x__829001280") AS "_q_0" WHERE "c" IS NULL AND TRUE\n'
374+
"Audit is warn only so proceeding with execution."
375+
)
376+
]
366377

367378
# Even though there are two builtin audits referenced in the above definition, we only
368379
# store the one that overrides `blocking` in the snapshot; the other one isn't needed

0 commit comments

Comments
 (0)