Skip to content

Fixes #28710: dbt test case uses test case name as TestDefinition instead of dbt test type#28927

Open
ulixius9 wants to merge 1 commit into
mainfrom
fix-dbt-test-definition-type
Open

Fixes #28710: dbt test case uses test case name as TestDefinition instead of dbt test type#28927
ulixius9 wants to merge 1 commit into
mainfrom
fix-dbt-test-definition-type

Conversation

@ulixius9

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #28710

dbt ingestion created OpenMetadata TestCases with both name and testDefinition populated from manifest_node.name. As a result:

  • Every test case's Test Type in the UI showed the test case name (e.g. unique_customers_customer_id) instead of the dbt test type (e.g. unique).
  • A single-use TestDefinition entity was created per test case instead of one shared definition per dbt test type, polluting the Test Definitions list.

Fix: add get_dbt_test_definition_name() in dbt_utils.py, which resolves the definition name from manifest_node.test_metadata.name (the dbt test type) and falls back to manifest_node.name for singular tests and source freshness checks, which have no test_metadata. Both create_dbt_tests_definition and create_dbt_test_case now use it, so all test cases of the same type share one TestDefinition.

This also handles namespaced package tests correctly — e.g. a dbt_utils.equal_rowcount test resolves to an equal_rowcount definition.

Backward compatibility: test cases ingested before this fix are skipped on re-ingestion (existing behavior — test cases are only created if absent), so they keep their old per-case definitions. Only newly created test cases get the shared type-based definition. Deleting the old test cases and re-running the ingestion migrates them.

Tests:

Use cases covered

  • dbt generic test (unique, not_null, accepted_values, relationships) → TestCase references a TestDefinition named after the dbt test type
  • dbt package test (dbt_utils.equal_rowcount) → resolves to equal_rowcount
  • Singular test (no test_metadata) → falls back to the node name (unchanged behavior)
  • Second test of an already-seen type → no duplicate TestDefinition created

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added: ingestion/tests/unit/test_dbt_test_definition.py (6 tests covering the helper, test case creation, definition creation, and dedup)
  • Existing dbt suites pass: test_dbt.py, test_dbt_ingest.py, test_dbt_http_config.py — 175/175

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Covered by unit tests on the dbt source processors; no connector connection logic changed.

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. Started local stack (MySQL + Elasticsearch + server) via docker/development/docker-compose.yml
  2. Reproduced the bug on the unpatched code with a dbt manifest (jaffle-shop, 20 generic tests): all 20 test cases had testDefinition equal to the test case name and 20 single-use TestDefinitions were created
  3. Re-ran the same ingestion with this fix: all 20 test cases reference the correct type and only 4 shared TestDefinitions exist (unique, not_null, accepted_values, relationships)
  4. Ran a second ingestion via the HTTP dbt config (dbt_git_test artifacts, 21 tests incl. dbt_utils.equal_rowcount): all test cases show the correct Test Type in the UI; data models, lineage, and descriptions unaffected

UI screen recording / screenshots:

Not applicable (ingestion-only change; UI now displays the correct Test Type).

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 added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

🤖 Generated with Claude Code

dbt test cases were created with both name and testDefinition populated
from manifest_node.name, so every test case got its own single-use
TestDefinition named after the test case instead of referencing the
actual dbt test type (e.g. unique, not_null) from
manifest_node.test_metadata.name.

Resolve the TestDefinition name from test_metadata.name for generic
tests, falling back to the node name for singular tests and source
freshness checks which have no test_metadata. Test cases of the same
type now share a single TestDefinition.

Fixes #28710

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ulixius9 ulixius9 requested a review from a team as a code owner June 10, 2026 12:57
Copilot AI review requested due to automatic review settings June 10, 2026 12:57
@github-actions

github-actions Bot commented Jun 10, 2026

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.

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Jun 10, 2026
@gitar-bot

gitar-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Updates dbt ingestion to resolve TestDefinition names based on the dbt test type instead of the test case name, ensuring shared definitions for identical test types. This change cleans up the Test Definitions list while maintaining backward compatibility for existing test cases.

💡 Edge Case: Shared TestDefinition entityType fixed by first test of a type

📄 ingestion/src/metadata/ingestion/source/database/dbt/metadata.py:1410-1424 📄 ingestion/src/metadata/ingestion/source/database/dbt/dbt_utils.py:691-699

With this change, all dbt tests of the same type now share a single TestDefinition named after test_metadata.name. The definition is created only once (the get_by_name dedup), so its entityType (TABLE vs COLUMN, computed in create_dbt_tests_definition from get_manifest_column_name(manifest_node)) is permanently determined by whichever test of that type is processed first. If a generic/custom test type is applied at both column level and table level across models, the shared definition will carry the wrong entityType for the other variant, since the definition is never recreated once it exists. For the standard built-in types (unique, not_null, accepted_values, relationships) this is consistent, but custom generic tests usable at either level can be mismatched. Consider keying/validating the definition by (test type, entityType) or documenting that mixed-level usage of one test type is unsupported.

🤖 Prompt for agents
Code Review: Updates dbt ingestion to resolve TestDefinition names based on the dbt test type instead of the test case name, ensuring shared definitions for identical test types. This change cleans up the Test Definitions list while maintaining backward compatibility for existing test cases.

1. 💡 Edge Case: Shared TestDefinition entityType fixed by first test of a type
   Files: ingestion/src/metadata/ingestion/source/database/dbt/metadata.py:1410-1424, ingestion/src/metadata/ingestion/source/database/dbt/dbt_utils.py:691-699

   With this change, all dbt tests of the same type now share a single `TestDefinition` named after `test_metadata.name`. The definition is created only once (the `get_by_name` dedup), so its `entityType` (TABLE vs COLUMN, computed in `create_dbt_tests_definition` from `get_manifest_column_name(manifest_node)`) is permanently determined by whichever test of that type is processed first. If a generic/custom test type is applied at both column level and table level across models, the shared definition will carry the wrong `entityType` for the other variant, since the definition is never recreated once it exists. For the standard built-in types (`unique`, `not_null`, `accepted_values`, `relationships`) this is consistent, but custom generic tests usable at either level can be mismatched. Consider keying/validating the definition by (test type, entityType) or documenting that mixed-level usage of one test type is unsupported.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

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

Fixes dbt ingestion so OpenMetadata TestCase.testDefinition is derived from the dbt test type (manifest_node.test_metadata.name) instead of the per-test-case node name, reducing TestDefinition entity pollution and making the UI “Test Type” accurate.

Changes:

  • Introduces get_dbt_test_definition_name() helper and uses it when creating dbt TestDefinition and TestCase entities.
  • Updates dbt ingestion to dedupe TestDefinition by test type (when available).
  • Adds unit tests validating the new test-definition naming behavior for generic and singular tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
ingestion/src/metadata/ingestion/source/database/dbt/dbt_utils.py Adds helper to compute the TestDefinition name for dbt tests.
ingestion/src/metadata/ingestion/source/database/dbt/metadata.py Switches TestDefinition / TestCase.testDefinition to use the helper instead of manifest_node.name.
ingestion/tests/unit/test_dbt_test_definition.py Adds regression tests for deriving TestDefinition from dbt test type.

Comment thread ingestion/src/metadata/ingestion/source/database/dbt/dbt_utils.py
Comment thread ingestion/tests/unit/test_dbt_test_definition.py
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

🔴 Playwright Results — 1 failure(s), 12 flaky

✅ 4271 passed · ❌ 1 failed · 🟡 12 flaky · ⏭️ 88 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 1 300 0 1 4
🟡 Shard 2 802 0 4 9
🟡 Shard 3 806 0 2 8
🟡 Shard 4 842 0 1 12
🟡 Shard 5 720 0 1 47
🔴 Shard 6 801 1 3 8

Genuine Failures (failed on all attempts)

Pages/LogsViewer.spec.ts › Logs page shows breadcrumb, summary, and log viewer or empty state after opening from bundle suite pipeline tab (shard 6)
Error: Failed to trigger pipeline b367af4a-7483-448c-9f86-0f7655f31f2d: 400
🟡 12 flaky test(s) (passed on retry)
  • Pages/Policies.spec.ts › Add new policy with invalid condition (shard 1, 1 retry)
  • Features/BulkImport.spec.ts › Keyboard Delete selection (shard 2, 1 retry)
  • Features/DataQuality/TestCaseImportExportE2eFlow.spec.ts › Admin: Complete export-import-validate flow (shard 2, 1 retry)
  • Features/DataQuality/TestCaseImportExportE2eFlow.spec.ts › EditAll User: Complete export-import-validate flow (shard 2, 1 retry)
  • Features/DataQuality/TestCaseResultPermissions.spec.ts › User with only VIEW cannot PATCH results (shard 2, 1 retry)
  • Features/Tasks/DomainFiltering.spec.ts › selecting All Domains removes domain filter from feed API call (shard 3, 1 retry)
  • Features/Workflows/WorkflowOssRestrictions.spec.ts › data-asset selector is disabled in OSS (shard 3, 1 retry)
  • Pages/CustomProperties.spec.ts › Markdown (shard 4, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard 5, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • Pages/Lineage/PlatformLineage.spec.ts › Verify domain platform view (shard 6, 1 retry)
  • Pages/ServiceEntity.spec.ts › User as Owner Add, Update and Remove (shard 6, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

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

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dbt test case uses test case name as TestDefinition instead of dbt test type

2 participants