Repository navigation
fix(test): resolve mocked and expected-row references consistently in SQL tests - #1023
Merged
Merged
Conversation
… SQL tests A mocked name now always means the mock in every SQL-test CTE: an assertion calling __ref() on a mocked model reads the mock instead of running the real model, and mocked models no longer count as test targets. References written directly in __expected__ CTEs are resolved like assertions and helpers. Compile reports unmocked __source(), __seed() and __dbt_ref() calls and unknown models in expected rows with P013. The native planner computes the models helpers and expected rows read itself and rejects any reference left raw.
A model-mode SQL test whose expected rows and assertions read only mocked names runs no model and used to be skipped silently. Compile now reports it with a located P013 diagnostic showing how to call __ref() on the model under test. Macro, UDF and table-function tests and scenarios keep their own targets.
…y mock-only errors The native planner now takes the helpers a test reads and the models its expected rows and helpers reference from the compiler, fails when a request omits them, and leaves unread helpers that call references out of the test query, so a helper named like a column no longer runs or fails a test. A reference the planner still cannot resolve is a located P013 instead of an unlocated P001. The error for a test that mocks the model it tests now explains how to mock the model's inputs instead.
kvlonge
force-pushed
the
fix/assertion-mock-references
branch
from
October 8, 2026 07:46
602b480 to
82c25be
Compare
kvlonge
enabled auto-merge (squash)
October 8, 2026 07:52
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.
Why
In SQL unit tests a mocked name did not always mean the mock: an
__assert__calling__ref("items")on a mockeditemsran the real model and made it a target. Calls in__expected__CTEs stayed raw and failed in the warehouse. The native planner trusted optional helper targets from Python. Tests reading only mocks were skipped silently.Changes
sqb test --select <mocked model>no longer selects the test.__expected__CTEs resolve like in assertions; an unmocked__ref()there runs that model.P013at compile for unmocked__source()/__seed()/__dbt_ref()in expected rows, assertions and read helpers, unknown models in expected rows, and model tests that mock the model they test (help: mock its inputs instead). Macro, UDF, table-function tests and scenarios are unaffected.P013.Verification
sql_analysis, incl. helpers named like columns and selection; three failure-corpus casescargo test --workspace --all-features,make compiler-differential,make compiler-differential-shipped,tests/e2e/scripts/compiler_differential,make check-ci,make test