Skip to content

BI-9790: extend mcr_source_or_ref to resolve cross-schema parents on improvado_models_staging#60

Merged
Solovechik merged 2 commits intomasterfrom
BI-9790-extend-mcr-source-or-ref-logic
Apr 3, 2026
Merged

BI-9790: extend mcr_source_or_ref to resolve cross-schema parents on improvado_models_staging#60
Solovechik merged 2 commits intomasterfrom
BI-9790-extend-mcr-source-or-ref-logic

Conversation

@Solovechik
Copy link
Copy Markdown
Contributor

@Solovechik Solovechik commented Apr 3, 2026

Summary

  • When target.schema == 'improvado_models_staging', the macro now queries system.tables to check if the parent model exists in any internal_analytics_dbt_staging_* schema and uses its fully-qualified name if found
  • Falls back to ref() if parent is in the same schema, then source() as a final fallback
  • All other environments (prod, personal staging) behave unchanged

Context

On staging, internal_analytics_src and internal_analytics models are built in internal_analytics_dbt_staging_* schemas. When a child model runs on improvado_models_staging, it needs to reference these parents by fully-qualified name since they live in a different schema.

A raw string is used because ref() and source() cannot point to arbitrary runtime schemas. This is acceptable since this code path is staging-only.

Replicated merge tree tables land in improvado_staging, but that schema is always a leaf — no models depend on it — so falling back to source() for those is correct.

Test plan

  • Run a model on improvado_models_staging whose parent was built in internal_analytics_dbt_staging_* — verify it resolves to the fully-qualified name
  • Run a model on improvado_models_staging whose parent is in the same schema — verify ref() is used
  • Run a model on improvado_models_staging with no parent in either schema — verify source() is used
  • Run on a personal staging schema — verify behavior is unchanged
  • Run in prod — verify source() is always used

🤖 Generated with Claude Code

Solovechik and others added 2 commits April 3, 2026 17:01
…improvado_models_staging

When target schema is improvado_models_staging, check internal_analytics_dbt_staging_*
schemas for the parent table and use its fully-qualified name if found, before falling
back to ref() or source().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Solovechik Solovechik enabled auto-merge (squash) April 3, 2026 12:20
@Solovechik Solovechik disabled auto-merge April 3, 2026 12:22
@Solovechik Solovechik merged commit 4d9ddd9 into master Apr 3, 2026
1 check failed
@Solovechik Solovechik deleted the BI-9790-extend-mcr-source-or-ref-logic branch April 3, 2026 12:29
@Solovechik Solovechik restored the BI-9790-extend-mcr-source-or-ref-logic branch April 3, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants