Skip to content

Pass macros to last audit in load_multiple_audits - #6160

Open
tylerjthomas9 wants to merge 1 commit into
SQLMesh:mainfrom
tylerjthomas9:fix/audit-macros
Open

tylerjthomas9 wants to merge 1 commit into
SQLMesh:mainfrom
tylerjthomas9:fix/audit-macros

Conversation

@tylerjthomas9

@tylerjthomas9 tylerjthomas9 commented Oct 23, 2026 •

Copy link
Copy Markdown

Description

load_multiple_audits didn't pass macros, jinja_macros or module_path to the last audit in a file. As a result, standalone audits using project Python or Jinja macros failed to load, which is always the case for single-audit files.

Reproduction

mkdir -p mwe/models mwe/macros mwe/audits && cd mwe
cat > config.yaml <<'YAML'
gateways: {local: {connection: {type: duckdb}}}
model_defaults: {dialect: duckdb}
YAML
echo 'MODEL (name db.m, kind FULL); SELECT 1 AS id' > models/m.sql
printf 'from sqlmesh import macro\n\n@macro()\ndef one(evaluator):\n    return 1\n' > macros/my_macros.py
printf 'AUDIT (name single_py, standalone true, depends_on [db.m]);\nSELECT * FROM db.m WHERE id <> @one()\n' > audits/single.sql

# sqlmesh 0.236.4: Error: ... Macro 'one' does not exist.
uvx --python 3.12 sqlmesh plan --auto-apply --no-prompts

With this fix, the plan applies and the audit passes.

Test Plan

Added test_load_multiple_standalone_with_macros, which fails without the fix. make fast-test passes.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant