Skip to content

fix: resolve the primary model of tests on versioned models - #1090

Open
masukai wants to merge 2 commits into
elementary-data:masterfrom
masukai:fix/primary-model-versioned-ref
Open

masukai wants to merge 2 commits into
elementary-data:masterfrom
masukai:fix/primary-model-versioned-ref

Conversation

@masukai

@masukai masukai commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

Fixes #1089.

For a test with more than one parent, the primary model is found from the test's model argument. A versioned model is rendered there as ref('my_model', version='1'), and its unique_id ends with the version (model.my_project.my_model.v1). The current lookup handles neither, so such tests get no parent_model_unique_id and no model_owners.

This change:

  • captures the arguments of ref(...) (name, and an optional version= / v=), so a versioned ref is matched
  • when a version is present, matches the parent whose unique_id ends with .<name>.v<version>; otherwise keeps the existing comparison with the last part of the unique_id

Unversioned refs and sources behave as before. It only uses single-group modules.re.findall, like the existing code.

Tests

  • Added test_relationship_test_on_versioned_model_uses_primary_model_owner to integration_tests/tests/test_dbt_artifacts/test_test_owners.py. It fails on master (parent_model_unique_id is None) and passes with this change.
  • pytest test_dbt_artifacts/test_test_owners.py --target duckdb (dbt-core 1.12.6, dbt-duckdb 1.11.0): 5 passed.
  • pre-commit run on the changed files: passed.

The new test is skipped for dbt Fusion and Dremio, like the existing relationship owner test next to it.

I ran the integration tests on DuckDB only (our own warehouse is BigQuery, where I did not run them). The change is plain Jinja with no warehouse-specific SQL, so I expect the other targets to behave the same, and I'll look at the CI results for the other warehouses.

Summary by CodeRabbit

  • Bug Fixes

    • Relationship tests for versioned dbt models now correctly resolve the specified model version.
    • Ownership reporting now includes only the owner of the tested versioned model, excluding owners from referenced models.
    • Versioned and unversioned model references continue to be matched appropriately, while source references remain supported.
  • Tests

    • Added integration coverage for ownership resolution in relationship tests on versioned models.

A test on a versioned model renders its model argument as ref('my_model', version='1'), and the model's unique_id ends with the version (model.my_project.my_model.v1). The primary model lookup handled neither, so such tests got no parent_model_unique_id and no model_owners. Capture the ref arguments (name and optional version/v) and match the parent whose unique_id ends with .<name>.v<version>; unversioned refs and sources behave as before.
@github-actions

Copy link
Copy Markdown
Contributor

👋 @masukai
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6124fe82-ba07-4939-9a20-76238f099c66
Commits

Reviewing files that changed from the base of the PR and between f9b3304 and 9fd5184.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The test artifact macro now parses optional versions in ref() arguments to resolve versioned parent models. An integration test checks that a relationship test uses the primary model’s owner and excludes the referenced model’s owner.

Changes: Versioned test model ownership

Layer / File(s) Summary
Resolve versioned test parent
macros/edr/dbt_artifacts/upload_dbt_tests.sql, integration_tests/tests/test_dbt_artifacts/test_test_owners.py
flatten_test parses optional versions in model references and matches parent IDs by model name and version. The integration test verifies that a relationship test resolves the versioned primary model and reports only its owner.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: elongl

Merge Risk: Minimal · previous review f9b33

No actionable issue was established. The change is mergeable after normal checks, although the versioned test’s coverage could not be independently confirmed.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: resolving the primary model for tests on versioned dbt models.
Linked Issues check Passed Issue #1089 requires primary-model resolution for multi-parent tests that use a versioned ref, including parent_model_unique_id and the primary model owner. The macro now captures ref names and …
Out of Scope Changes check Passed The changes are limited to the primary-model lookup in upload_dbt_tests.sql and an integration test for the linked issue. The parsing and matching changes directly support issue #1089. No unrelated …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 …
Full details: Linked Issues check

Explanation

Issue #1089 requires primary-model resolution for multi-parent tests that use a versioned ref, including parent_model_unique_id and the primary model owner. The macro now captures ref names and optional v or version values, matches IDs ending in .&lt;name&gt;.v&lt;version&gt;, and keeps the existing unversioned and source paths. The added integration test covers a relationship test on a versioned model and verifies the primary model and owner behavior. The reported DuckDB test run passed.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the primary-model lookup in upload_dbt_tests.sql and an integration test for the linked issue. The parsing and matching changes directly support issue #1089. No unrelated product behavior or unrelated files are shown in the supplied change summary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 unsupported.)

Finishing Touches

🧪 Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
ℹ️ Recent review info

⚙️ Run configuration

  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 703e614a-7e52-434e-9c53-7e830496cf0e
📥 Commits

Reviewing files that changed from the base of the PR and between e3ab23d and f9b3304.

📒 Files selected for processing: 2

  • integration_tests/tests/test_dbt_artifacts/test_test_owners.py
  • macros/edr/dbt_artifacts/upload_dbt_tests.sql

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@jonlevine7

jonlevine7 commented Nov 27, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@haritamar
haritamar deployed to elementary_test_env November 27, 2026 22:30 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
elementary_test_env — 9fd51842 Deployed Nov 27, 2026 by haritamar via approve-fork #5395
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.

Tests on versioned models get no primary model (and no owners) in dbt_tests

3 participants