Skip to content

fix(unitycatalog): name Databases after the catalog names Unity Catalog stores - #37112

Closed
akashverma0786 wants to merge 11 commits into
mainfrom
fix/unitycatalog-high-bugs
Closed

akashverma0786 wants to merge 11 commits into
mainfrom
fix/unitycatalog-high-bugs

Conversation

@akashverma0786

@akashverma0786 akashverma0786 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

No linked issue: this bug comes from a live audit of the Unity Catalog connector against a Databricks workspace (OpenMetadata 2.1.0, 0d18bb8e0a2). It was reproduced with real ingestion on two fresh services, with a control that passed in the same runs, and the fix was verified the same way. The connector code is identical on main and 2.1, so it is present on both.

A catalog configured in mixed case loses all lineage.

  • catalog: Demo became Database Demo. The system tables report demo, and lineage builds svc.demo… and looks it up by exact name, so every target missed. Live: emitted 0 edges over 15 targets and 0 edges, while the run reported 100 % success. Metric-view lineage warned that every source was "not in OpenMetadata".
  • Unity Catalog stores catalog, schema and table names lowercase and resolves them case-insensitively. The docs say so, and I checked live: creating QA_UC_CaseChk stores qa_uc_casechk, the second spelling fails with SCHEMA_ALREADY_EXISTS, and catalogs.get('DEMO').name is demo.
  • This has been broken since Fix #25615 - Use system tables instead of API for lineage in UC #25697 (1.12.0) moved lineage to the system tables; 1.10 and earlier used the REST lineage API, which ignores case.
  • Fix: the Database takes the name catalogs.get() returns (lowercased text only if that call fails). Text the connector parses, a metric view's YAML source, is lowercased before lookup. New record: ADR:2026-11-05-unity-catalog-databases-take-the-name-unity-catalog-stores.

Behavior change to note in the release:

  • A service ingested before this change with a mixed-case catalog gets a second, lowercase Database on its next run. With markDeletedDatabases off (the default), the old one keeps its curated metadata and goes stale until it is deleted. With it on, that run soft-deletes the old Database and everything under it; restoring it brings the curated metadata back, but the next such run deletes it again. No migration renames it: the server cannot rename a Database today (renameAllowed is off).

Type of change:

  • Bug fix

High-level design:

  • Connector only. The changes are in unitycatalog/metadata.py and unitycatalog/metric_view_lineage.py, with no schema, server or UI change.
  • Names come from Unity Catalog's API (catalogs.get), never from the typed text.
    • The catalog is resolved once per run, in a cached_property, so the progress totals and the walk agree.
    • The CatalogInfo it fetched is reused by yield_database, as before.
  • Alternatives rejected:
    • Keeping the typed name and making every lookup case-insensitive. This needs the same change in lineage, metric-view lineage and the incremental audit query, and it keeps names depending on the config.
    • A rename migration: the server does not support renaming a Database.

Tests:

Use cases covered

  • catalog: Demo / DEMO: Database demo, one catalogs.get shared by totals and walk; unreadable catalog falls back to lowercase; metric-view YAML relations in capitals resolve; an inherited scope is kept as ingested.

Unit tests

  • I added unit tests for the new/changed logic. All 7 new test cases fail on main and pass on this branch.
  • Files added/updated:
    • new: tests/unit/topology/database/test_unitycatalog_configured_scope.py;
    • extended: tests/unit/topology/database/test_unitycatalog_metric_view_lineage.py.
  • Ran: the 12 test_unitycatalog* unit test files, 225 passed; and every unit test file that mentions Unity Catalog or Databricks (67 files), 1406 passed. The 2 failures and 8 collection errors are all optional drivers missing from the local venv (sqlalchemy_exasol, teradatasqlalchemy, looker_sdk, mlflow, pyhive, snowflake, trino, validators).
  • Coverage on changed modules (the 12 test_unitycatalog* files): unitycatalog/metadata.py 82 %, unitycatalog/metric_view_lineage.py 94 %.
  • ruff check / ruff format --check clean; scripts/check_ruff_suppressions.py --check passes; basedpyright --baselinefile .basedpyright/baseline.json --baselinemode=discard on the two source files: 0 errors.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable: there is no tests/integration/ suite for Unity Catalog or Databricks. Real ingestion runs against a live workspace are listed below instead.

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Real MetadataWorkflow and lineage workflow runs from a CLI venv against a live Databricks workspace (SQL warehouse, PAT) and a local OpenMetadata 2.1 server, each on fresh services. Before = original code, after = this change. The catalog-name code in this PR is the same code these runs used.

  1. catalog: Demo and catalog: DEMO, metadata + lineage. Before (2): Database Demo/DEMO, emitted 0 edges over 15 targets. After (2): Database demo, 15 edges, identical to the lowercase-demo control.
  2. Metric view mv_caps with source: DEMO.QA_UC_A.ORDERS. Before (2): source relation [DEMO.QA_UC_A.ORDERS] is not in OpenMetadata, no edge. After (2): edge demo.qa_uc_a.orders → demo.qa_uc_mvcase.mv_caps with column lineage (amount → total_amount, status → order_status), no warning.

UI screen recording:

Not applicable — ingestion-only bug fix, no UI change.

Checklist:

  • I have read the CONTRIBUTING document.

  • My PR title is Fixes <issue-number>: <short explanation> — no issue: found by a live connector audit, details above.

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

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

  • For JSON Schema changes: not applicable, no schema change.

  • For a UI feature or feature task: not applicable.

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

  • Self-review: I reviewed the diff against REVIEW.md and fixed every 🔴 finding.

    • Reviewed at 7174865021d. The final diff only removes the failed-listing change from it; the catalog-name code is unchanged.
  • Decision check: adds docs/decisions/2026-11-05-unity-catalog-databases-take-the-name-unity-catalog-stores.md.

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

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge with the documented upgrade behavior.

Summary

Unity Catalog databases now use the catalog name returned by its API. Metric-view lineage lowercases relation names written in YAML while preserving inherited database and schema names.

  • Unity Catalog Databases now use the name returned for the configured catalog.
  • Metric-view lineage now matches relation names regardless of typed capitalization.

Reviews (11) · Last reviewed commit: "fix(unitycatalog): leave the failed-list..." · Reviewed by Greptile

… name Databases as Unity Catalog stores them, never delete after a failed listing

- databaseSchema on the connection now restricts the walk to that schema (schemas.get), and the
  progress totals count only it.
- An email owner resolves only by its (lowercased) email; the fallback to a user named after the
  email's local part assigned assets to a different person. Shared with the Databricks connector.
- A configured catalog is ingested under the name catalogs.get returns, so lineage, metric-view
  lineage and incremental extraction match it for any casing typed; metric-view YAML relations are
  lowercased before lookup. ADR:2026-11-05-unity-catalog-databases-take-the-name-unity-catalog-stores.
- A catalog, schema or table listing that fails partway no longer drives markDeleted* for its
  scope, and a run that skipped a due cleanup fails with WorkflowFatalError.
@akashverma0786
akashverma0786 requested a review from a team as a code owner November 5, 2026 07:39
@akashverma0786 akashverma0786 added the safe to test Add this label to run secure Github workflows on PRs label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

akashverma0786 and others added 2 commits November 13, 2026 12:46
…er resolution as on main

- The stale-database cleanup now lists the catalogs before it checks for a failed
  listing. With a configured catalog that listing is the run's only catalog listing,
  and a failure there used to soft-delete every Database it did not return.
- Restore the Databricks owner resolver and its tests to main. Its email local-part
  fallback was added on purpose in #28466; changing it is out of scope here.
- Keep the base "No Database found in the context" guard in the table cleanup, and
  annotate the mark_schemas/mark_databases overrides.
- Test the full-mode table cleanup by the scopes it sends, and make the failed
  table page test fail on main.
- Prune the two G004 baseline entries for the logger calls this branch removed.
@akashverma0786 akashverma0786 changed the title fix(unitycatalog): honour databaseSchema, match owners by email only, use Unity Catalog catalog names, keep tables after a failed listing fix(unitycatalog): honour databaseSchema, use Unity Catalog catalog names, keep tables after a failed listing Nov 15, 2026
…cleanup

The progress totals listed the catalogs through the walk's failure-recording
listing, so a failed count marked the catalog listing as failed: the database
cleanup was skipped and the run failed although the walk saw every catalog.
The totals now list the catalogs directly, as the Databricks and Redshift
totals do; a failure only costs the denominator, and the progress runner
warns and goes on.
… catalog

With `databaseSchema` set and `catalog` left blank, the walk asked every catalog
for that schema, and a catalog without it counted as a failed listing: its
stale cleanup was skipped and every run failed with WorkflowFatalError.

- The walk treats a NotFound for the configured schema as "not in this catalog"
  when no catalog is configured. With a configured catalog, a missing schema is
  still a recorded failure, and any other error still is too.
- Test Connection looked for the schema only in the first listed catalog, so the
  run could not start when that catalog lacked it. With no configured catalog it
  now uses the first catalog that has the schema, and fails only when none has it.
…atabase consequence

- New record ADR:2026-11-15-unity-catalog-runs-fail-when-a-failed-listing-skipped-their-cleanup
  states how Unity Catalog applies the REVIEW.md rule, what does not count as a failed
  listing, and why a listing that fails on every run fails every run. `_iter` cites it
  instead of the Tableau record, which covers only Tableau's backfill.
- The catalog-naming record said the old mixed-case Database goes stale. That holds with
  markDeletedDatabases off; with it on, the first run soft-deletes it, and a restore is
  undone by the next run.
…-bugs

# Conflicts:
#	ingestion/src/metadata/ingestion/source/database/unitycatalog/metadata.py
#	ingestion/tests/unit/topology/database/test_unity_catalog_connection.py
@akashverma0786 akashverma0786 added the skip-pr-checks Bypass PR metadata validation check label Nov 16, 2026
@ulixius9

Copy link
Copy Markdown
Member

Upgrade impact: a failed listing now fails the whole run

Skipping stale cleanup for a scope whose listing failed is the right fix. But making the run end with WorkflowFatalError reaches further than it looks:

  • markDeletedTables defaults to true, so this applies to almost every existing Unity Catalog service, not just ones that chose a markDeleted* option.
  • A listing that fails on every run, such as PERMISSION_DENIED on one schema the service principal can't read, used to give a partial-success run. After upgrade every run of that service fails, whatever successThreshold is, and that will look like a regression in alerts and retries.
  • The Tableau record this builds on (ADR:2026-10-22-…) chose not to fail the run for failures that recur, for exactly this reason. The new record accepts that cost. I think it needs a more visible mitigation than a line in the release note.

Some options, roughly from least to most change:

  1. Keep the fatal error, but say it plainly in the release note and the connector docs. The way out (fix the grant, exclude the scope with a filter, or turn off markDeletedTables) should be in the error message itself so support can point to it.
  2. Record the skipped cleanup as a status.failed that counts against successThreshold instead of a WorkflowFatalError. A scope that keeps failing then shows up as a partial failure rather than turning the whole run red, and still nothing is deleted.
  3. Raise only for errors likely to be transient (5xx, timeouts) and record permission and not-found errors as ordinary failures. Those happen every run and stay the same until someone changes a grant.

There's also an inconsistency: some failed-listing paths still finish green while skipping cleanup (the re-listing inside _mark_listed_tables_as_deleted, and a failed catalog listing when only markDeletedTables is on). So today the rule isn't consistently "a skipped cleanup fails the run" either way.

A failed catalog, schema or table listing still skips the stale cleanup of
what it did not reach, but no longer raises WorkflowFatalError. The listing
failure is the one recorded error and counts against successThreshold, so a
listing that fails on every run (a missing grant) shows as a partial success
instead of failing every run. Its message says nothing it missed was deleted
and how to clear a recurring failure.

Replaces the unmerged 2026-11-15 decision record with
ADR:2026-11-19-a-failed-unity-catalog-listing-skips-its-stale-cleanup-without-failing-the-run.
@akashverma0786

Copy link
Copy Markdown
Collaborator Author

@ulixius9 Thanks, went with option 2 in 7174865.

  • A failed listing still skips the stale cleanup for what it did not reach, but the run no longer raises WorkflowFatalError. The listing failure is the one recorded error and counts against successThreshold. Its message says nothing it missed was deleted, and that a failure on every run is cleared with a grant or a filter pattern.
  • This also closes the gaps you pointed out: the cleanups' own catalog and schema listings follow the same rule, so every failed listing behaves the same way.
  • Tested with real ingestion on a Databricks workspace and an injected HTTP 500: nothing in the failed scope was deleted, the run ended as partialSuccess (and failed with successThreshold: 99), and a clean rerun still deleted the stale entities.
  • This departs from REVIEW.md's "fail the workflow regardless of successThreshold" for Unity Catalog. The reason is in ADR:2026-11-19-a-failed-unity-catalog-listing-skips-its-stale-cleanup-without-failing-the-run. If you want option 2 as the general rule, I can update REVIEW.md in a separate PR.

Restore the Unity Catalog databaseSchema handling to main: the walk lists
every schema again, the progress totals count every filtered schema, and
Test Connection checks the configured schema in the resolved catalog only.
The catalog-name and failed-listing fixes are unchanged.
@akashverma0786 akashverma0786 changed the title fix(unitycatalog): honour databaseSchema, use Unity Catalog catalog names, keep tables after a failed listing fix(unitycatalog): use Unity Catalog catalog names, keep tables after a failed listing Nov 19, 2026
# catalog's schemas, (catalog, schema) for a schema's tables. What such a listing
# did not reach was not seen, so stale-entity cleanup must leave the scope alone.
self._incomplete_listings: set[tuple[str, ...]] = set()
self.owner_resolver = DatabricksOwnerResolver(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We don't want to do this. We will tackle soft deletion improvements at a later date in a central manner.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @IceS2 for the review, made the required changes.

…s PR

Soft-deletion after a failed listing will be handled centrally, as asked in review.
This PR now carries only the catalog-name fix.
@akashverma0786 akashverma0786 changed the title fix(unitycatalog): use Unity Catalog catalog names, keep tables after a failed listing fix(unitycatalog): name Databases after the catalog names Unity Catalog stores Nov 20, 2026
@gitar-bot

gitar-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 2 closed / 2 findings

Normalizing configured catalog names changes database identity; with markDeletedDatabases enabled, the old mixed-case database and its descendants could be soft-deleted.

Unity Catalog Databases are now named after the catalog name catalogs.get() returns, so mixed-case catalog configs no longer lose lineage, and metric-view YAML sources are lowercased before lookup. Resolved the missing record for the fail-the-run-on-skipped-cleanup rule and the silent skip of schemas when relisting fails during table cleanup. No issues found.

✅ 2 closed
✅ Quality: Fail-the-run-on-skipped-cleanup rule for Unity Catalog has no record

📄 ingestion/src/metadata/ingestion/source/database/unitycatalog/metadata.py:949-963 📄 docs/decisions/2026-11-05-unity-catalog-databases-take-the-name-unity-catalog-stores.md:1-15
This PR adds a new deletion-safety rule for Unity Catalog, but no record in docs/decisions/ states it. The one ADR it adds covers only catalog naming. _iter cites ADR:2026-10-22-tableau-runs-stop-without-deleting-while-the-metadata-api-backfills, but that record decides the rule for Tableau's BACKFILL_RUNNING only.

That Tableau record also argues against applying the same rule to failures that recur. Its Consequences section says such failures "can recur on every run ... so failing the run would block that site for good." Unity Catalog listing failures can recur in exactly that way: a schema whose table listing returns PERMISSION_DENIED fails on every run. markDeletedTables defaults to on, so after this change every run of that service ends in WorkflowFatalError, whatever successThreshold is. Before, the same failure was an ordinary recorded failure.

The rule comes from the description: "A failed listing scope (catalogs, a catalog's schemas, or a schema's tables) is remembered and its stale-entity cleanup is skipped" and "When a skipped cleanup was due, the run fails with WorkflowFatalError once the topology finishes, regardless of successThreshold." A record would state: "A Unity Catalog run whose catalog, schema or table listing fails skips stale cleanup for that scope and, when that cleanup was enabled, fails with WorkflowFatalError whatever successThreshold is." It should also explain why a listing failure that recurs every run (for example a permission error) should block the service, which the Tableau record chose to avoid.

The repository squash-merges, so without a record this rule exists only in the PR description and in a comment that cites a Tableau-only ADR.

✅ Edge Case: Failed schema relisting in table cleanup skips schemas silently

📄 ingestion/src/metadata/ingestion/source/database/unitycatalog/metadata.py:1102-1107
_mark_listed_tables_as_deleted checks (catalog_name,) in _incomplete_listings before it calls _get_filtered_schema_names. That call lists the catalog's schemas again through get_database_schema_names → _iterate_listing. If this second listing fails partway, _iterate_listing adds the scope only after the check has already passed, so the loop just ends early. Table cleanup for the schemas it never reached is skipped, and nothing is appended to _skipped_stale_cleanups. mark_schemas_as_deleted has already run for this catalog, so nothing catches the gap later. _iter then doesn't raise, and the run passes the success threshold even though the 2026-11-15 ADR says it should fail. mark_databases_as_deleted already handles this case by checking after it lists. Collect the schema names first, then check the scope.

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

@IceS2 IceS2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@akashverma0786, this looks good but it is potentially a breaking change since we will be renaming assets from every person using this, right?

Shouldn't we have a migration for this? @ulixius9 if you could also check this out

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

Labels

safe to test Add this label to run secure Github workflows on PRs skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants