372 this unit test fix#490
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the execution-aware source model loading logic to avoid calling load_relation(this) in dbt unit test contexts where this is not a Relation (it can be str/None), preventing compilation-time crashes across macros that use source_model_processing.
Changes:
- Add short-circuit guards (
this is none,this is string,model.resource_type == 'unit_test') beforeload_relation(this)is evaluated. - Preserve existing behavior for normal model runs by falling through to the original
load_relation(this) is none or should_full_refresh()logic whenthisis a Relation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
dbt test combined result: ❌ DetailsRESULTS for Synapse: RESULTS for Postgres: RESULTS for BigQuery: RESULTS for Redshift: RESULTS for Snowflake: RESULTS for Exasol: RESULTS for Fabric: RESULTS for Oracle: RESULTS for Databricks: RESULTS for SQL Server: RESULTS for Trino: Link to workflow summary: https://github.com/ScalefreeCOM/datavault4dbt-ci-cd/actions/runs/29258502305 |
|
dbt test combined result: ❌ DetailsRESULTS for Synapse: RESULTS for Postgres: RESULTS for BigQuery: RESULTS for Redshift: RESULTS for Snowflake: RESULTS for Exasol: RESULTS for Fabric: RESULTS for Oracle: RESULTS for Databricks: RESULTS for SQL Server: RESULTS for Trino: Link to workflow summary: https://github.com/ScalefreeCOM/datavault4dbt-ci-cd/actions/runs/29262601161 |
Description
In dbt unit tests,
thisis not a Relation object — depending on the dbt version it is astrorNone. The execution-aware loading logic insource_model_processing(
macros/supporting/source_models.sql) calledload_relation(this)unguarded, whichcrashed at compile time when accessing
.database:'str object' has no attribute 'database'(as reported in the issue)'None' has no attribute 'database'(observed during testing on a different dbt version)This broke unit tests for all entity macros using
source_model_processing(hubs, links, nh_links, ref_hubs, rec_track_sats — all adapters).
The fix adds short-circuiting guards before
load_relation(this):never called with a non-Relation value. (Note: appending a guard after
load_relation(this) does not work — the crash happens before the guard is reached.)
model.resource_type == 'unit_test' catches the unit test context semantically as a
safety net for future dbt versions.
as an initial load / --full-refresh, which is correct since unit tests mock their
inputs and should compile against the full model logic rather than a runtime selection.
model.resource_type == 'model', so evaluation falls through to the original
load_relation(this) is none or should_full_refresh() logic unchanged.
Single-line change; this is the only load_relation(this) call site in the package.
Fixes #372 from the product development milestones:
https://github.com/ScalefreeCOM/product_development_milestones/issues/372
Type of change
How Has This Been Tested?
source_model_processing now compile and pass with
multi_source_models__execution_aware_loading enabled. The temporary workaround
(datavault4dbt.multi_source_models__execution_aware_loading: false) is no longer needed.
dbt version with 'None' has no attribute 'database' — confirming both guards are needed.
unit test context; relation exists / missing / --full-refresh in normal runs): unit
tests never invoke load_relation; normal runs behave exactly as before.
Test Configuration:
Checklist: