fix(macros): resolve_template fails in audits when this_model is a subquery - #5931
Open
sravankumarkunadi wants to merge 1 commit into
Open
Conversation
…bquery Signed-off-by: sravankumarkunadi <sravankumarkunadi@users.noreply.github.com>
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
@resolve_templateraisesAttributeError: 'Subquery' object has no attribute 'catalog'in an audit attached to a model with atime_column(so, anyINCREMENTAL_BY_TIME_RANGEmodel).The macro assumes
@this_modelis a table and calls.catalog/.db/.nameon it. ButModel.render_audit_queryonly passes a table when there's no time filter — otherwise it passes a subquery restricting the physical table to the audited range:exp.to_table()returns non-Tableexpressions untouched, so theSubqueryreaches.catalogand raises. #3991 fixed thewhere is Nonebranch; the time-column branch still produces the subquery.This unwraps the subquery to the table it selects from before resolving the template.
@this_modelis unchanged — audits still get the time-filtered subquery — only the catalog/schema/table lookup reaches through it, which is what those placeholders mean. That makesmode := 'table'usable in audits that need the full materialized table rather than the current batch.Closes #5927
Test Plan
test_resolve_template_subquery(test_macros.py) —mode := 'table'with a subquerythis_model; fails onmainwith the reportedAttributeError.test_resolve_template(test_audit.py) — end to end throughrender_audit_queryon an incremental model, both modes; the literal case also asserts@this_modelstill renders as the time-filtered subquery.pytest tests/core/test_macros.py tests/core/test_audit.py tests/core/test_model.py -m "not slow and not docker"→ 487 passed vs 485 onmain(the 2 new tests). Both runs hit the same 27 errors, allConfigError: Materialization strategy ... was not found— test fixture entry points missing from my venv, none in the two files touched here.make styleclean on the changed files.Checklist
make styleand fixed any issuesmake fast-test) — ran the three files above rather than the full suite, see the pre-existing local errors noted theregit commit -s) per the DCO