Repository navigation
Fixes #38042: validate RDF inverse pairs before registration - #38147
Conversation
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
Keep a symmetric property's self-reference while leaving its named partner without an inverse. A one-way B-to-A link beside A's self-inverse changes B-authored edges to A during UUID canonicalization. Retain fresh-state partner completion, cover both UUID orderings with a three-term HTTP regression, and trim inverse-wiring comments to constraints.
Resolve inverse predicates to their governed types and prepare every new candidate before saving any pair. Skip invalid pairs together so validation cannot leave the first type pointing at an absent partner. Recheck existing claims before insertion and before partner updates, clearing our new inverse when either check loses. Preserve fresh governed fields while making the remaining non-atomic window explicit. Exercise actual symmetric wiring, record the identity-preserving rule, and cover contradictory partners, predicate reuse, and controlled concurrent claims through real HTTP integration tests.
f9fb754 to
a236bcb
Compare
…tric-inverse-partner
Complete an existing partner with updateIfCurrent on an unchanged original, treating a stale version or a late validation failure as a lost claim that clears the new type's inverse. Resolve authored and inverse predicates against the registry and the current batch, so one predicate never gets two types. Run the same read-only validation in dry runs, limit rejection to types actually wired to an invalid one, and name every skipped type. Replace the MySQL trigger and named lock with portable JDBI gates, giving the pre-insert, post-insert, compare-and-set and partner-validation checks their own failing-without-it tests. Record the governed-predicate, skip-as-a-whole and lost-claim rules in a decision record.
When the partner's version comparison fails, re-read it once: accept a partner that now points at the new type, retry the conditional write once when it is still unclaimed, and clear the new inverse only when another type claimed it or it keeps changing. Concurrent imports making the same claim and unrelated partner edits no longer leave a one-way pair. Validate new definitions before wiring inverse pairs. A rejected definition no longer claims a partner that declares no inverse, so the partner pairs with the next valid claimer regardless of IRI order; a definition whose own declaration names a rejected one is still skipped with it. Move the in-batch predicate test to a unit test with an injected resolver instead of deleting the seeded skos:related row, add same-claim and unrelated-edit gate cases plus the reverse-sorted claimer variant, align the decision record with the code, and drop a redundant impact-map entry.
When a relationship type in the imported file failed validation, the real import still tried to add each edge that used it and reported "Relationship type '<t>' is not registered" per edge, while the dry run dropped those edges silently. Counts matched, but the two runs returned different messages, and the real-run wording hid the cause. Both runs now skip edges whose type was skipped as invalid before reaching the repository, with one message per edge: "Relation <t> skipped: its relationship type '<t>' was skipped as invalid".
Code Review ✅ Approved 🔴 High risk 3 closed / 3 findingsRDF import now validates and conditionally updates shared relationship-type inverse pairs; concurrency failures could leave conflicting claims or inconsistent registry state. Fixes RDF import so inverse pairs are validated before registration, with invalid definitions skipped and reported instead of half-saving a pair, and governed predicates reused rather than aliased. Resolved the missing decision records for the symmetric-partner and import rules, and the invalid type claiming a shared inverse partner before validation. No open issues remain. ✅ 3 closed✅ Quality: Symmetric-partner inverse rule is not recorded in docs/decisions
✅ Quality: Import rules for governed reuse, pair skipping and lost claims lack ADR
✅ Edge Case: Invalid type can claim a shared inverse partner before validation runs
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
| private void clearPersistedInverse(UUID typeId, UUID partnerId) { | ||
| RelationshipType current = registry.get().require(typeId); | ||
| if (current.getInverse() != null && partnerId.equals(current.getInverse().getId())) { | ||
| current.setInverse(null); | ||
| overwriteRelationType(current); |
There was a problem hiding this comment.
Cleanup overwrites concurrent edits. When an existing partner is claimed elsewhere or cannot be completed,
clearPersistedInverse reads the newly saved type and then passes that snapshot to createOrUpdate. A different user can edit its description or inverse between those calls. createOrUpdate loads the newer row as its baseline but writes the older snapshot over it, silently losing that edit—even when its version advanced.
Use an unchanged original and a copy with updateIfCurrent for cleanup too. After a conflict, re-read and clear only an inverse that still names the rejected partner.
Knowledge Base Used: Metadata entity lifecycle
#38147 was squash-merged into main; conflicts resolved against its PR head, so this PR's diff is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M4KprReeYHb7DDyP4ujmSX
Describe your changes:
Fixes #38042
Follow-up to #38069, its symmetric-partner finding, and Gitar's decision-record requests (1, 2), and its shared-partner finding.
RDF import now keeps authored B edges beside symmetric A and resolves every predicate (authored edge or inverse target) by RDF identity. It reuses the governing registry type or a type already planned in the same batch, so one predicate never gets two types and no alias such as
exactMatchappears beside seededsynonym.Every new definition is validated before inverse pairs are wired, and again before any is saved, in real imports and dry runs alike. A failing definition is skipped, together with any new definition whose own
owl:inverseOfnames it. Its declaration no longer claims a partner that declares no inverse, so that partner pairs with the next valid claimer whatever the IRI order. Each skipped type is named, and the import returns HTTP 200 with accurate counts where main returned 400 after half-saving the pair.Existing partners are rechecked before new types are inserted and again after insertion. The partner is then completed with
EntityRepository.updateIfCurrent. If the version comparison fails, the partner is re-read once:Type of change:
High-level design:
Extends the existing importer registration pipeline and
RelationshipTypeResolver.findByPredicate. In order: resolve governed identities by predicate, prepare every candidate read-only and drop invalid ones (with definitions that declare them as inverse), wire candidate pairs, refresh existing partners, prepare again and discard invalid wired components, then persist accepted types. The partner completion is a version compare-and-set on an unchanged original and a deep copy, with one re-read after a lost comparison.Known limits:
updatedAtas well (asKnowledgePageRepositorydoes) would need a relationship-type storage override; not done here.No schema or migration changes.
Tests:
Use cases covered
GlossaryRdfImportConcurrencyIT. The tests use a portable JDBI statement gate, with no MySQL trigger or named lock, and touch only rows they create:gamma owl:inverseOf betadeclaration no longer takes down the valid alpha/beta pair, whether gamma's IRI sorts before or after alpha's.X owl:inverseOf skos:exactMatchreuses seededsynonym, with no alias. An edge authored with a governed predicate uses its governed name.skos:relatedplusex:mirrors owl:inverseOf skos:relatedin one batch registers one type forskos:related. This is a unit test with an injected resolver; the IT that deleted and re-inserted the seeded row is removed.Unit tests
GlossaryRdfImporterTest: 19 passed, 0 skipped. Changed-class line coverage was not measured.Backend integration tests
72c69ec1814(edge messages for skipped types):GlossaryRdfImporterTest19/19,GlossaryRdfImportIT40/40,GlossaryRdfImportConcurrencyIT6/6, 0 skipped, on the same command with-Dit.test=GlossaryRdfImportIT,GlossaryRdfImportConcurrencyIT. The table below is the earlier full run.PASSED — focused mysql-elasticsearch verification of the tree committed as
8aa654e2b10.Total: 242 executed, 32 inherited skips, 0 failures/errors, plus 19 unit tests. The same run also executed a temporary HTTP-recording subclass of the concurrency IT (6 cases, not committed): Failsafe reported 280 run. Per-class counts are grouped by testcase classname because parallel Failsafe reports mix suite headers.
mvn -B -Dmaven.repo.local="$PWD/.context/m2" verify \ -pl :openmetadata-integration-tests -am \ -Dspring-boot.repackage.skip=true -Dresolve.skip=true \ -Pmysql-elasticsearch -DintegrationTests.lane=parallel \ -Dit.test=GlossaryRdfImportIT,GlossaryTermRelationEdgeIT,RelationshipTypeResourceIT,RelationshipTypeContradictionIT,GlossaryRdfImportConcurrencyIT \ -Dfailsafe.failIfNoSpecifiedTests=false \ -Dtest=GlossaryRdfImporterTest -Dsurefire.failIfNoSpecifiedTests=falseThe live before/after table below came from a temporary local HTTP probe IT, which is not committed.
Production-only regression proof: each check kept the committed tests, reverted one production fix, and ran the matching tests with the compiled override first on the classpath (its load location verified). Each failed at its intended assertion, with 0 skips:
sameClaimBeforePartnerWriteKeepsTheNewInverse,unrelatedEditBeforePartnerWriteStillCompletesThePairimportDoesNotRejectAValidPairForAnUnwiredInvalidDeclaration[true][false]passed[true][false]passedimportSkipsInvalidInversePairWithoutSavingEitherHalf(both)72c69ec1814, full Maven run with the old importer)importSkipsInvalidInversePairWithoutSavingEitherHalf(both)collectRelationTypesRegistersOnePredicateOnceAcrossEdgeAndInverseSlots[skosRelated], was[related, skosRelated]claimAfterDiscoveryIsRejectedBeforeInsertion0.1, was0.2claimAfterInsertionClearsThePersistedInversetrue, wasfalseupdateIfCurrentpartner writeclaimBeforePartnerWriteIsNotOverwrittenwinner, wasforwardpartnerValidationFailureClearsTheNewInverseThe unchanged tests for authored-predicate reuse and dry-run validation were revert-proven on
b21ffa44f92.After restoring the source, the 10 selected API cases and all 19 unit tests passed.
mvn -B -Dmaven.repo.local="$PWD/.context/m2" spotless:check -pl openmetadata-service,openmetadata-integration-tests python3 .github/scripts/plan_local_java_tests.py --check-branch python3 scripts/harness/check_decision_records.py git diff --checkAll passed. Other engines, full repository coverage and CI monitoring were not run.
Ingestion integration tests
Not applicable — no ingestion changes.
Playwright (UI) tests
Not applicable — backend importer changes; no Playwright run.
Visual regression baselines
Not applicable — no rendering changes.
Manual testing performed
Built the real application against MySQL + Elasticsearch on allocated ports, authenticated as admin, and issued real import, relationship-type GET, term GET and concurrent PATCH requests. No credentials are included here.
skos:exactMatch)exactMatchsynonymunchanged, no aliasskos:relatededge +ex:mirrors owl:inverseOf skos:relateda236bcb: import 200;relatedandskosRelatedboth onskos:relatedskos:related, no duplicatesa236bcb: import 200; competing claim overwritten (partner back to inverse=A, edits lost)a236bcb: import 400 after A was saved pointing at Ba236bcb: already fixedb21ffa44f92: import 200, "changed while completing"; A's inverse cleared, leaving B→A one-wayb21ffa44f92: import 200, "changed while completing"; pair droppedUI screen recording:
Not applicable — backend-only bug fix.
Checklist:
Fixes #38042identify the linked issue.8aa654e2b10against REVIEW.md.🤖 Generated with Claude Code
Fix the cleanup write before merging so dropping an inverse pair cannot erase concurrent edits.
Findings
Summary
RDF imports now reuse governed relationship types, reject invalid definitions before saving, and protect existing inverse partners from competing edits.
fmcardoso documents the accepted limits: same-user edits that keep their version can be overwritten, registration is not one transaction, and rejected components do not remove previously stored definitions.
Reviews (2) · Last reviewed commit: "Report relations of a skipped RDF relati..." · Reviewed by Greptile