Skip to content

372 this unit test fix#490

Open
polat-deniz wants to merge 2 commits into
mainfrom
372_this_unit_test_fix
Open

372 this unit test fix#490
polat-deniz wants to merge 2 commits into
mainfrom
372_this_unit_test_fix

Conversation

@polat-deniz

Copy link
Copy Markdown
Collaborator

Description

In dbt unit tests, this is not a Relation object — depending on the dbt version it is a
str or None. The execution-aware loading logic in source_model_processing
(macros/supporting/source_models.sql) called load_relation(this) unguarded, which
crashed 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):

{% if this is none or this is string or model.resource_type == 'unit_test' or load_relation(this) is none or should_full_refresh() %}
  • Jinja evaluates or chains left-to-right with short-circuiting, so load_relation is
    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.)
  • this is none / this is string cover both observed unit-test representations;
    model.resource_type == 'unit_test' catches the unit test context semantically as a
    safety net for future dbt versions.
  • In unit test context the condition reverts to all source models — the same behavior
    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.
  • No behavior change for normal runs: there, this is always a Relation and
    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

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Tested end-to-end with the customer who reported the issue: unit tests on models using
    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.
  • The intermediate state with only a this is string guard still failed on the customer's
    dbt version with 'None' has no attribute 'database' — confirming both guards are needed.
  • Verified the condition logic against all six states (this = None / str / Relation in
    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:

  • datavault4dbt-Version: branch 372_this_unit_test_fix (based on main)
  • dbt-Version: cloud/core, version number
  • dbt-adapter-Version: dbt-snowflake, version number

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation or included information that needs updates (e.g. in the Wiki)

@polat-deniz polat-deniz added the testing To trigger the automated test workflow as internal User. label Jul 13, 2026
@polat-deniz polat-deniz requested a review from Copilot July 13, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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') before load_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 when this is a Relation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread macros/supporting/source_models.sql
Comment thread macros/supporting/source_models.sql
@tkiehn tkiehn added the waiting-on-maintainers Waiting for a response from the maintainers. label Jul 13, 2026
@remoteworkflow

Copy link
Copy Markdown

dbt test combined result: ❌


Details

RESULTS for Synapse:
❌ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Postgres:
✅ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for BigQuery:
✅ dbt-core-tests
✅ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Redshift:
✅ dbt-core-tests
✅ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Snowflake:
✅ dbt-core-tests
✅ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Exasol:
❌ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Fabric:
❌ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Oracle:
✅ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Databricks:
❌ dbt-core-tests
❌ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for SQL Server:
✅ dbt-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Trino:
✅ dbt-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


Link to workflow summary: https://github.com/ScalefreeCOM/datavault4dbt-ci-cd/actions/runs/29258502305

@remoteworkflow remoteworkflow Bot removed the testing To trigger the automated test workflow as internal User. label Jul 13, 2026
@remoteworkflow

Copy link
Copy Markdown

dbt test combined result: ❌


Details

RESULTS for Synapse:
❌ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Postgres:
✅ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for BigQuery:
✅ dbt-core-tests
✅ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Redshift:
✅ dbt-core-tests
✅ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Snowflake:
✅ dbt-core-tests
✅ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Exasol:
❌ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Fabric:
❌ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Oracle:
❌ dbt-core-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Databricks:
❌ dbt-core-tests
❌ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for SQL Server:
❌ dbt-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


RESULTS for Trino:
✅ dbt-tests
⚠️ dbt-fusion-tests
⚠️ dbt-macro-tests
⚠️ tech-tests


Link to workflow summary: https://github.com/ScalefreeCOM/datavault4dbt-ci-cd/actions/runs/29262601161

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

Labels

waiting-on-maintainers Waiting for a response from the maintainers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use MAX(LDTS) earlier when using multiple rsrc_static

3 participants