Repository navigation
fix!: pass macros to the last audit in load_multiple_audits - #6120
Open
markussagens wants to merge 1 commit into
Open
markussagens wants to merge 1 commit into
markussagens wants to merge 1 commit into
Conversation
The final load_audit call in load_multiple_audits did not pass module_path, macros or jinja_macros, so the last (or only) AUDIT in a file was loaded with an empty python_env and no project jinja macros. Rendering a standalone audit that used a project macro then failed with "MacroEvalError: Macro '<name>' does not exist." Affected standalone audits now include the macros they reference, which changes their metadata hash and fingerprint. Fixes SQLMesh#6119 Signed-off-by: Markus Sagen <markus@studio555.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #6119.
load_multiple_auditspassedmodule_path,macrosandjinja_macrostoload_auditinside its loop, but not in the finalyield load_audit(...). So the lastAUDITin a file (the only one, for a one-audit file) was loaded with an emptypython_envand an empty Jinja macro registry. Rendering a standalone audit that used a project macro then failed withMacroEvalError: Macro '<name>' does not exist.The final call now passes the same three arguments as the call inside the loop. The other arguments already matched.
Fingerprint impact (
!): an affected standalone audit now stores the macros it references, so its metadata hash and fingerprint change. After upgrading,sqlmesh planwill list it as a metadata-only change. These audits failed to render before, so nothing that previously worked changes behavior.Test Plan
Three regression tests in
tests/core/test_audit.py. All three fail without the fix and pass with it:test_load_multiple_single_standalone_with_macros: one-audit file using a project Python macro.test_load_multiple_last_standalone_with_macros: two-audit file where only the last audit uses the macro.test_load_multiple_last_standalone_with_jinja_macros: last/only audit using a project Jinja macro.pytest tests/core/test_audit.pypasses (46 tests). Also ran the issue's reproduction project end to end:Context(...).standalone_audits["only_allowed"].render_audit_query()now renders.Checklist
make styleand fixed any issues (ranruff check,ruff formatandmypyon the changed files)make fast-test) (onlytests/core/test_audit.pywas run locally)git commit -s) per the DCO🤖 Generated with Claude Code