Skip to content

Fixes 38654: Never attach a dbt relationships test to the table it references - #38656

Open
ulixius9 wants to merge 3 commits into
mainfrom
ulixius9/collate-slack-investigate
Open

ulixius9 wants to merge 3 commits into
mainfrom
ulixius9/collate-slack-investigate

Conversation

@ulixius9

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #38654

A dbt relationships test was attached to the table it references (to:) whenever the tested model's table was not in OpenMetadata. parse_upstream_nodes_with_names drops upstreams it can't find. Then get_dbt_test_primary_table_fqn could resolve neither the model ref nor a single non-to: candidate, and fell back to upstream_list[0]. dbt lists the referenced parent first, so that is the to: table. The server then rejected the test with 400 Invalid column name <fk_col> on every run, which left the pipeline at Partial Success. If the column name existed on both tables, the test landed on the wrong table silently.

When the tested model doesn't resolve, the to: table is now excluded and a remaining upstream is used only if exactly one is left. If none or several are left, the test is skipped with one warning per test that names the model (missing or filtered out). Several remaining candidates happen, for example, when an ephemeral model is expanded into its parents. Tests without a to: (singular tests, other generic tests, freshness) keep the first-upstream fallback. This is a follow-up to #28911 / #30606, which fixed the alias/case mismatch but kept the upstream_list[0] fallback.

Seen in a production dbt Cloud + Snowflake run: 3 of its 12 nightly Invalid column name failures came from this path. The other 9 were schema.yml columns the tables don't have, and the server correctly rejects those.

Type of change:

  • Bug fix

High-level design:

N/A — small change (one function in dbt_utils.py plus its tests).

Tests:

Use cases covered

  • Relationships test whose tested model's table is not in OpenMetadata → skipped with a warning (previously attached to the to: table and rejected with a 400).
  • Relationships test whose unresolved tested model leaves several candidates (e.g. an ephemeral model) → skipped, rather than an arbitrary pick or the to: table.
  • Existing behaviour unchanged: alias/case resolution, source() namespaces, single-upstream tests.

Unit tests

  • Added test_dbt_relationships_test_skipped_when_tested_table_not_in_openmetadata and test_dbt_relationships_test_skipped_when_tested_table_is_ambiguous in ingestion/tests/unit/test_dbt.py. Both fail on main and pass with the fix.
  • pytest tests/unit/test_dbt.py tests/unit/test_dbt_python_models.py tests/unit/test_dbt_test_definition.py tests/unit/test_dbt_test_descriptions.py: 377 passed, 1 failed. The failure is TestStorageStreamingBehavior::test_gcs_passes_generator_to_grouping (module 'google.cloud' has no attribute 'storage'), because my local venv lacks google-cloud-storage; it is unrelated to this change.
  • ruff check / ruff format --check on the changed files: clean.
  • Coverage % not measured.

Backend integration tests

  • Not applicable (no backend changes).

Ingestion integration tests

  • Not applicable. No test under tests/integration/ imports dbt_utils.

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. Read the full DEBUG logs of 7 consecutive nightly runs of an affected dbt Cloud + Snowflake pipeline (2.0.8 and 2.0.9). Confirmed the relationships failures were created against the to: table while Unable to find the table '<tested model>' was logged for the tested model.
  2. Called generate_entity_link on the 2.0.9 code with a synthetic relationships test node. With the tested model missing from upstreams, it returned the referenced table's link; with the fix, it returns [].

UI screen recording:

Not applicable — ingestion-only bug fix.

Checklist:

  • I have read the CONTRIBUTING document.

  • My PR title is Fixes <issue-number>: <short explanation>

  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.

  • I have commented on my code, particularly in hard-to-understand areas.

  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. — N/A, no schema change.

  • For a UI feature or feature task: … — N/A, no UI.

  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
    Reviewed 9f338dabe16 with a fresh-context reviewer. The first pass (6a022f8555e) found 0 🔴 and 2 🟡: an arbitrary pick among several candidates, and a duplicate warning that showed raw Jinja. Both are fixed in 9f338dabe16, and the re-review found nothing. Known limitation, unchanged from main: an ephemeral tested model with exactly one parent still attaches to that parent.

  • Decision check — N/A: no new contract, default or ordering. The rule "never attach to the to: table" is stated in the code docstring.

  • I have added a test that covers the exact scenario we are fixing.

🤖 Generated with Claude Code

…erences

When the tested model's table is not in OpenMetadata it is dropped from the
test's upstreams, and the primary-table fallback picked upstream_list[0] -
the relationships test's to: table, which dbt lists first. The test was
attached to that table with a column it does not have and the server
rejected it with 400 Invalid column name, or it landed on the wrong table
silently when the column happened to exist on both.

The fallback now picks the first upstream that is not the referenced table
and skips the test with a warning when none is left.
Trust a non-to: candidate only when exactly one remains, so an unresolved
tested model with several candidates (an ephemeral model expanded into its
parents) is skipped rather than attached to an arbitrary upstream. Log the
skip from generate_entity_link so it is emitted once per test, naming the
model instead of its raw Jinja.
@ulixius9
ulixius9 requested a review from a team as a code owner November 25, 2026 07:14
@ulixius9
ulixius9 requested review from Khairajani and a balanced review from Copilot November 25, 2026 07:14
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

The skip also happens when several candidate tables exist in OpenMetadata,
so blaming a missing or filtered table sent readers looking for a table that
is there.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 07:23

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@gitar-bot

gitar-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findings

Changing dbt relationship-test resolution to skip missing or ambiguous models could reduce reported test coverage, though it prevents misattachment.

Stops dbt relationships tests from attaching to the to: table when the tested model is missing from OpenMetadata. The test is now skipped with a per-test warning naming the model, unless exactly one non-to: upstream remains. Resolved the skip warning that misstated the cause when the fallback was ambiguous.

✅ 1 closed
✅ Quality: Skip warning misstates the cause when the fallback is ambiguous

📄 ingestion/src/metadata/ingestion/source/database/dbt/dbt_utils.py:878-887 📄 ingestion/src/metadata/ingestion/source/database/dbt/dbt_utils.py:829-831
generate_entity_link logs the same message for every unresolved test: the model's table "is not among its upstreams found in OpenMetadata (missing or filtered out)". _resolve_without_model also returns None when removing the to: table leaves two or more candidates, which is the case covered by test_dbt_relationships_test_skipped_when_tested_table_is_ambiguous. In that case the tables are in OpenMetadata, and the test is skipped because the pick would be arbitrary. A user who reads the log will look for a missing or filtered table that is actually there. Fix: give the ambiguous case its own message that lists the candidates, e.g. have _resolve_without_model report why it returned None, or check the candidate count before logging.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch has not been deployed

No deployments
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.

dbt relationships test attached to the referenced table when the tested model's table is not in OpenMetadata

2 participants