Skip to content

Fixes #30679: detach conflicting data products on data product domain change - #32944

Merged
sonika-shah merged 10 commits into
mainfrom
fix/30679-dataproduct-domain-detach
Sep 21, 2026
Merged

sonika-shah merged 10 commits into
mainfrom
fix/30679-dataproduct-domain-detach

Conversation

@sonika-shah

@sonika-shah sonika-shah commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #30679

Describe your changes

Changing a Data Product's domain re-homes its assets to the new domain, but left behind any other data product still assigned to those assets whose domain no longer matched. The affected assets then failed the default Data Product Domain Validation rule on every subsequent edit (400 RULE_VIOLATION), and a reindex could not recover the state because the mismatch is persisted, not an indexing artifact. The Data Product domain change was the only route that let this through — the Domain page move, changing an asset's own domain, and cross-domain assignment are all already handled or rejected.

After the existing asset-domain migration in DataProductRepository.updateDataProductDomains, this detaches the now-conflicting data-product assignments, mirroring the Domain page cleanupDataProducts behaviour:

  • Direct assets — for each migrated asset, any assigned data product whose domains no longer intersect the asset's new domains is detached (relationship + lineage removed, caches invalidated, asset reindexed).
  • Inherited-domain descendants — the check walks the containment subtree of each migrated asset. A descendant that inherits its domain (no explicit domain of its own) is reconciled against the new inherited domain; the walk stops at any node that carries its own domain, since it and its subtree are unaffected. This covers the reported case where a child table assigned to a data product that stayed behind broke identically, even though only its parent was the moved product's asset.

The detach reuses the validation rule's exact disjoint-domain semantics, so matching assignments — including the moved data product itself — are preserved and nothing is over-detached. A data product with no domains never conflicts.

The whole step is gated on the Data Product Domain Validation rule being enabled. When the rule is disabled the mismatch is a legal configuration and assignments are left untouched, matching pre-existing behaviour.


Deferred to a fast-follow (kept out to keep this diff focused): enriching the rule-violation message to name the offending data product and domain. That requires threading specifics out of the boolean JsonLogic operation in the shared rule engine — a different, cross-cutting concern. With this fix these domain-change flows no longer trigger the violation in the first place.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Tests

Added two integration tests in DataProductResourceIT, both verified RED without the fix and GREEN with it (full class green, no regressions):

  • test_domainChangeDetachesConflictingDataProducts — a schema in Finance assigned to two data products (both in Finance); moving one to HR detaches the one left behind, keeps the moved one, and the schema stays editable.
  • test_domainChangeDetachesConflictingDataProductsOnInheritedDescendants — a child table inheriting its schema's domain and assigned to a data product that stays in Finance; moving the schema's data product to HR detaches the child's conflicting assignment and the child stays editable.

The rule-disabled branch is not covered by an integration test because the IT harness cannot toggle the global rule at runtime (see the pre-existing @Disabled tests noting EntityRulesUtil.toggleRule not working via API); the gate is exercised via the enabled default path.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previously reported correctness issues are fixed and no new actionable failures remain.

Summary

The PR reconciles data-product assignments after a data product’s domains change, removing assignments that conflict with migrated or inherited asset domains.

  • Traverses inheriting descendants in bounded hydration chunks and prunes explicitly domained subtrees.
  • Removes conflicting relationships and lineage, invalidates caches, and defers batched reindexing until commit.
  • Adds integration coverage for direct assets, inherited descendants, soft-deleted assets, and domain removal.
  • Exposes rule-enabled lookup so cleanup runs only when domain validation is active.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Data product domains change] --> B[Migrate direct asset domains]
  B --> C{Domain validation rule enabled?}
  C -- No --> Z[Leave assignments unchanged]
  C -- Yes --> D[Reconcile direct assets]
  D --> E[Walk containment levels]
  E --> F{Child has explicit domain?}
  F -- Yes --> G[Prune child subtree]
  F -- No --> H[Use inherited parent domains]
  H --> I{Assignment conflicts?}
  I -- No --> E
  I -- Yes --> J[Remove relationship and lineage]
  J --> K[Invalidate asset cache]
  K --> L[Queue asset for reindex]
  L --> E
  E --> M[Defer batched reindex until commit]
Loading

Reviews (8) · Last reviewed commit: "perf: bound descendant reconciliation me..."

… change

Moving a data product's domain re-homes its assets to the new domain but left any
other data product still assigned to those assets (or to descendants that inherit
their domain) whose domain no longer matched. Those assets then failed the
"Data Product Domain Validation" rule on every subsequent edit, and a reindex could
not recover the persisted mismatch.

After the asset domain migration, detach the now-conflicting data-product assignments
from the direct assets and from inherited-domain descendants, mirroring the Domain
page cleanup. Gated on the validation rule being enabled; when the rule is disabled
the mismatch is a legal configuration and is left untouched. Detach uses the rule's
exact disjoint-domain semantics, so matching assignments (including the moved data
product itself) are preserved.
@sonika-shah
sonika-shah requested a review from a team as a code owner September 8, 2026 09:34
Copilot AI lite review requested due to automatic review settings September 8, 2026 09:34

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 reached their quota limit.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 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.

- Detach every data product from an asset left with no domains: the
  validation rule fails any asset that has data products but no domains,
  so clearing a data product's domains must also drop the assignments.
  conflictsWithDomains now treats an empty effective-domain set as a
  conflict, mirroring validateDataProductDomainMatch. Covered by a new IT.
- Reconcile inherited-domain descendants against the parent asset's own
  effective domains rather than the moved data product's new domains, so a
  descendant's valid assignment to one of the asset's other domains is not
  wrongly detached when multiple domains per asset are allowed.

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 reached their quota limit.

Replace the per-node recursive walk with a level-by-level BFS that batches its
reads (findToBatchAllTypes / findFromBatch), and collect detached assets for a
single batched reindex (updateEntitiesByReference) instead of one search write
per asset.

Behaviour is unchanged: same disjoint-domain detach semantics, same
soft-deleted skipping, same rule gate. The query cost drops from O(nodes in the
asset subtree) to O(tree depth), so a data product assigned to a
schema/database/service no longer fans out to tens of thousands of queries
inside the domain-change transaction.

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 reached their quota limit.

…ciliation

Two regressions from the previous batching commit, both invisible to the IT
suite (it runs with caching off and does not assert search state):

- Descendant refs were built from relationship rows and carried no FQN, so
  invalidateCacheForEntity skipped the by-name cache eviction (guarded by
  fqn != null) and a detached asset stayed cached with its stale data-product
  until TTL. Resolve the detached assets through EntityUtil.populateEntityReferences
  (batched per type, FQN filled in place) before detaching.

- The batched reindex ran un-deferred inside the domain-change @transaction, so
  updateEntitiesByReference re-read uncommitted rows. Wrap it in
  deferIfFlushScopeActive so it runs post-commit against committed state, per
  that method's documented contract.

Also add a visited-set guard to the descendant BFS so it terminates on a
containment cycle or a node reached via multiple parents.

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 reached their quota limit.

The batched BFS still loaded an entire tree level at once (findToBatchAllTypes
+ batchFetchDomainIds accumulate every row), so peak heap was O(widest level) —
a data product on a database/service with hundreds of thousands of tables could
OOM on that single load.

Reduce each level's children to lightweight (id, type) refs immediately and do
the heap-heavy work (own-domain lookup, data-product lookup, detach + reference
hydration) in bounded chunks of DESCENDANT_RECONCILE_CHUNK_SIZE, mirroring
bulkHardDeleteSubtree's per-level chunking. Peak heap is now ~O(chunk *
tree-depth) of hydrated state plus the level's lightweight id refs, instead of
the whole level hydrated at once.

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 reached their quota limit.

@gitar-bot

gitar-bot Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Code Review ✅ No issues found 4 closed / 4 findings

🟡 Medium risk

Detaches conflicting data product assignments when a data product's domain changes, preventing migrated assets and inherited-domain descendants from violating the Data Product Domain Validation rule. Soft-deleted assets are now properly skipped, recursive queries have been batched by traversal level to bound memory use, descendants are reconciled against the correct domain set, and descendant cache invalidation has been corrected. Added integration tests covering direct conflicts, inherited descendants, and soft-deleted assets.

✅ 4 closed
✅ Edge Case: Soft-deleted asset/child aborts the domain change

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java:1226-1231 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java:1295-1302
getContainedChildren (line 1300) and the asset loop (line 1228) resolve every relationship record with Entity.getEntityReferenceById(type, id, NON_DELETED). relationshipDAO().findTo returns containment/HAS records regardless of the target's soft-deleted state, and getEntityReferenceById(..., NON_DELETED) throws EntityNotFoundException for a soft-deleted (or missing) entity. So a single soft-deleted asset assigned to the data product, or a soft-deleted child anywhere in a migrated asset's containment subtree, makes the detach step throw and rolls back the entire data-product domain change. Resolve with ALL and skip entities whose getDeleted() is true (or catch/ignore the not-found case) so stale relationships to deleted entities don't abort the operation.

✅ Performance: Recursive per-node DB queries over full asset subtree in txn

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java:1239-1253
detachConflictingDataProductsFromDescendants recurses over the entire containment subtree of each migrated asset, and every node issues several separate queries (getContainedChildren, ownDomainIds, getDataProducts, plus per-conflict lineage/cache/search work), all inside the domain-change transaction. For an asset such as a schema or database with thousands of descendants this is an N+1 walk that can make the PATCH slow and hold the transaction open. Consider batching the child/domain/data-product lookups per level, or bounding the walk, if large hierarchies are expected.

✅ Bug: Descendants reconciled against wrong domain set

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java:1202-1216 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java:1202-1214
For a direct asset, detachConflictingDataProductsAfterDomainChange correctly reconciles data products against ownDomainIds(asset) — the asset's full effective domain set after migration. But it walks the descendant subtree with newDomainIds (the moved data product's new domains) instead. batchMigrateAssetDomains only removes the moved DP's old domains and adds its new domains, so a direct asset that carries an additional, unrelated domain keeps it: its effective set becomes {newDomains} ∪ {extras}, and descendants with no own domain inherit that full set. Because descendants are checked against the smaller newDomainIds, a descendant's data product whose domain matches one of the parent's extra domains is treated as disjoint and detached — a valid assignment (relationship + lineage) is silently removed. The Javadoc states descendants "inherit this asset's new domains," which is the direct asset's effective domains, confirming the intended set is ownDomainIds(asset).

✅ Bug: Descendant refs lack FQN, by-name cache not invalidated

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java:1250 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DataProductRepository.java:1362-1365
In reconcileInheritingDescendants, descendant assets are built as bare references: new EntityReference().withId(childId).withType(row.getToEntity()) (line 1250) — EntityRelationshipObject carries no FQN, so fullyQualifiedName is null. These refs flow into removeDataProductAssignments, which calls invalidateCacheForEntity(type, id, asset.getFullyQualifiedName()). With a null FQN, invalidateCacheForEntity skips the CACHE_WITH_NAME eviction and bumpWriteEpoch skips WRITE_EPOCH_BY_NAME (both guarded by if (fqn != null)). The Guava by-name cache entry for the descendant therefore keeps the stale entity still holding the just-detached conflicting data product until TTL. A subsequent get-by-name returns that stale asset, which fails the Data Product Domain Validation rule again (400 RULE_VIOLATION) — reintroducing, for inherited descendants, the very failure this PR fixes. The previous code obtained descendants via findTo(...), whose references had FQN populated, so the by-name cache was correctly invalidated.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

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 was previously deployed

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

Labels

backend 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.

Data Product domain change leaves conflicting data product assignments, making assets unwritable

3 participants