Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1742fc0
Fixes #38112: reject deleting a relationship type that is still in use
fmcardoso Nov 18, 2026
6c29b65
Guard the settings path and make the type repair safe to re-run
fmcardoso Nov 18, 2026
1924afa
Preserve named relation types beside symmetric inverse partners
fmcardoso Nov 18, 2026
7955b75
Drop the type repair and fix the settings-path review findings
fmcardoso Nov 18, 2026
a236bcb
Validate RDF inverse pairs before registration
fmcardoso Nov 18, 2026
4151a58
Merge remote-tracking branch 'origin/main' into fmcardoso/38112-relat…
fmcardoso Nov 18, 2026
596328a
Merge remote-tracking branch 'origin/main' into fmcardoso/38042-symme…
fmcardoso Nov 18, 2026
ca73305
Restore soft-deleted types before an RDF import references them
fmcardoso Nov 18, 2026
b21ffa4
Close the RDF inverse partner write window and reuse batch predicates
fmcardoso Nov 18, 2026
6ec8a83
Let either side of an unused inverse pair be deleted
fmcardoso Nov 18, 2026
8aa654e
Keep RDF inverse pairs complete under concurrent partner edits
fmcardoso Nov 18, 2026
2bc3ecb
Merge remote-tracking branch 'origin/fmcardoso/38042-symmetric-invers…
fmcardoso Nov 18, 2026
0c72af5
Move the relationship type reference guard out of the repository
fmcardoso Nov 18, 2026
4d68eca
Restore a soft-deleted type an RDF import names, found by its predicate
fmcardoso Nov 18, 2026
72c69ec
Report relations of a skipped RDF relationship type in dry runs too
fmcardoso Nov 18, 2026
864aaa0
Address the review of the relationship type guard and import restore
fmcardoso Nov 18, 2026
0d12a6c
Merge remote-tracking branch 'origin/fmcardoso/38042-symmetric-invers…
fmcardoso Nov 18, 2026
b8a205d
Assert the relations behind a name held by a deleted type are reporte…
fmcardoso Nov 18, 2026
fc03fbc
Merge origin/main into fmcardoso/38112-relationship-type-delete-guard
fmcardoso Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# A relationship type in use cannot be deleted

- **Status:** Accepted
- **Revisions:** v1 2026-11-18 (initial)
- **Deciders:** Ontology Studio team
- **Guard:** `RelationshipTypeDeleteGuardIT`, `GlossaryRdfImportIT`, `RelationshipTypeReferencesTest`, `RelationshipTypeRdfWriterTest`, `LegacyRelationshipTypeSynchronizerTest`
- **Related:** #38112, ADR:2026-11-17-recreating-a-deleted-ontology-name-restores-its-record

## Context
Other relationship types name a type as their `inverse`, `replacedBy`, a `propertyChain` member or
a `disjointWith` member, and glossary term relations store the type by name and id. Relations are
stored from the lower term id, so one authored as `A` from the higher id is stored as `A`'s
inverse. Every reader resolves these against live types, so deleting a type in use made term reads,
lists, edits and the ontology export of the affected glossaries fail with 400. Only system types
were protected from deletion.

## Decision
1. A soft or hard delete of a relationship type is rejected with 400 while another type, live or
soft-deleted, names it in `replacedBy`, `propertyChain` or `disjointWith` (matched by id, FQN or
name, its own references excluded), or while any stored glossary term relation, including those
of soft-deleted terms, is stored as it. The message names those types and counts the relations.
2. Another type naming it as its `inverse` does not block the delete: the delete clears each live
partner's `inverse` in the same transaction, as a versioned change of the partner by the
deleting user with its own change event. The partner is written only if it is unchanged since
the delete read it; otherwise the delete fails with 412 and nothing is written. The delete is
still rejected while a relation is stored as such a partner: relations are stored from the lower
term id, so one authored as the deleted type from the higher id is stored as the partner, and
every relation stored as the partner reads as the deleted type from its other end. Clearing the
inverse would make those read as the partner at both ends, so only a pair with no relation stored
as either side loses a side. A soft-deleted partner keeps its back-link; it holds no relation.
3. A restored type keeps its `inverse` only as one half of a pair. A live partner with no inverse and
no stored relation is linked back, under the same unchanged-since-read condition; otherwise the
restored type's inverse is cleared. A one-way link would read a relation authored as the restored
type from the higher term id back as the partner. The restored type holds no relation (it could
not be deleted with one or gain one while deleted), so clearing its inverse changes no reading,
while re-linking a used partner would change how the partner's relations read. The link back
takes the shape of the restored type's own inverse reference (with or without a name), the shape
the pair was written in. Only a deleted type can be restored; restoring a live one is rejected
with 400 before anything is written.
4. A create or update whose references name a soft-deleted type is rejected with 400. A reference
by FQN to a type that does not exist yet stays allowed (the UI creates an inverse pair that
way); the ontology export omits such an axiom instead of failing. An RDF import that names the
predicate of a soft-deleted type restores that type first, and skips a new type whose name a
soft-deleted type holds on another predicate
(ADR:2026-11-18-rdf-import-registers-governed-inverse-components). A term relation naming a
soft-deleted type is rejected with the same "is deleted; restore it first" message.
5. The deprecated settings write removes several types at once: the whole removal is checked before
the setting is saved, against the definitions that write saves, and references among the removed
types do not block it, whether they hold them by id or by FQN alone. A kept type's inverse naming
a removed type is cleared as in rule 2. A listed type that is soft-deleted is brought back before
the others. The removal runs in one transaction, so a delete refused by a concurrent change
leaves every type in place rather than a partial removal; the setting itself is saved first.
6. Dependents are never cascaded: relations are never deleted or retyped, and an `inverse` is cleared
only when no relation reads through it.
7. No repair ships for types deleted earlier: that was possible only on unreleased 2.1/main builds
and the 2.1.0 pre-releases, and restoring the type (soft delete) or recreating it under the same
name, with its inverse, through the API (hard delete) makes those reads work again.

## Consequences
Reads stay consistent without tolerant fallbacks. Deleting one side of an unused inverse pair just
works and leaves the other side without an inverse; relations added to it afterwards are stored and
read as that type at both ends, like any type without an inverse. Restoring the deleted side links
the pair again while the other side is still unused. When both sides were deleted, restoring the one
deleted last first and then the other rebuilds the pair; the other order leaves both without an
inverse. To delete a type that relations or other definitions use, an admin first removes them.

A relation write and a type delete are each validated on their own, not locked against each other.
Any glossary editor writing relations can race an admin's delete for as long as the writer's
transaction is open: a relation stored as the type (or as a partner whose inverse the delete
clears) after the delete counted relations commits next to a deleted type. The outcome is the
original failure for that glossary: its term reads, list, edits and ontology export fail with 400
until the type is restored (soft delete) or recreated under its name (hard delete). MySQL compares
type names in binary after converting the stored name to utf8mb4, since the column takes the
database character set.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# RDF import preserves governed predicates and validates inverse components before registration

- **Status:** Accepted
- **Revisions:** v1 2026-11-18 (initial); v2 2026-11-18 (validate before wiring; re-read a partner after a lost version comparison)
- **Revisions:** v1 2026-11-18 (initial); v2 2026-11-18 (validate before wiring; re-read a partner after a lost version comparison); v3 2026-11-18 (a soft-deleted type on a named predicate is restored, not aliased)
- **Deciders:** OpenMetadata maintainers
- **Guard:** GlossaryRdfImporterTest#collectRelationTypesRegistersOnePredicateOnceAcrossEdgeAndInverseSlots; GlossaryRdfImportIT#importReusesTheGovernedNameOfAnAuthoredPredicate; GlossaryRdfImportIT#importSkipsInvalidInversePairWithoutSavingEitherHalf; GlossaryRdfImportIT#importDoesNotRejectAValidPairForAnUnwiredInvalidDeclaration; GlossaryRdfImportConcurrencyIT
- **Related:** #38042, #38069, #38147; ADR:2026-11-18-rdf-import-symmetric-inverse-partners-stay-unlinked
- **Guard:** GlossaryRdfImporterTest#collectRelationTypesRegistersOnePredicateOnceAcrossEdgeAndInverseSlots; GlossaryRdfImportIT#importReusesTheGovernedNameOfAnAuthoredPredicate; GlossaryRdfImportIT#importSkipsInvalidInversePairWithoutSavingEitherHalf; GlossaryRdfImportIT#importDoesNotRejectAValidPairForAnUnwiredInvalidDeclaration; GlossaryRdfImportIT#importRestoresASoftDeletedInverseFoundByItsPredicate; GlossaryRdfImportIT#importSkipsANameHeldByADeletedTypeOnAnotherPredicate; SoftDeletedRelationTypesTest; GlossaryRdfImportConcurrencyIT
- **Related:** #38042, #38069, #38147, #38140; ADR:2026-11-18-rdf-import-symmetric-inverse-partners-stay-unlinked, ADR:2026-11-18-a-relationship-type-in-use-cannot-be-deleted

## Context

Expand All @@ -16,6 +16,8 @@ Use RDF predicate identity for both authored edges and inverse targets. Reuse th

Validate every new definition before wiring inverse pairs, in real imports and dry runs alike. A definition that fails is skipped with a message naming it, and so is any new definition whose own `owl:inverseOf` declaration names a skipped one. A skipped definition's declaration does not claim a partner that declares nothing: that partner pairs with the next valid claimer, or with none. After wiring, the definitions are validated again; a failure there skips every new member wired to the failing one and cancels their pending existing-partner updates. Other valid definitions can import. The import returns HTTP 200 with skips and accurate counts rather than failing the whole import with HTTP 400.

A predicate the import names, as an edge or a declared inverse, that only a soft-deleted type holds brings that type back rather than registering a new one beside it, which a later restore would leave as a second live type on the predicate. Only the predicate decides, one type per predicate (the most recently changed when several soft-deleted types hold it), and nothing is restored onto a predicate a live type holds. A soft-deleted type that holds only the name the import would register is never restored: its predicate differs, and restoring it would move the authored edges onto that predicate. Registering a new type under that name would overwrite the deleted one by name, so that new type is skipped with a message naming the deleted type's predicate (restore or rename it), as any other skipped definition. A real import restores the type before collecting definitions, so validation and wiring see a live, governed type whose stored definition is kept; restoring it applies its own inverse rule (a stale inverse is cleared or its unused partner linked back) and records a restore change event. A dry run restores nothing: it reports the type as one it would restore and validates and wires against it as that restore would leave it.

Refresh existing partners before publishing new types, and again before completing a partner. Complete it with EntityRepository.updateIfCurrent on an unchanged original and a copy, so a stale update cannot overwrite a newer version. When the version comparison fails, re-read the partner once. If it now points at the new type, the pair is complete. If it is still unclaimed (only an unrelated edit happened), retry the conditional write once. If another type has claimed it, or it changes again, keep that edit and clear the new type's inverse before adding its edges. A partner-completion validation failure likewise clears the new inverse and reports the skipped update.

## Consequences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.openmetadata.it.factories.GlossaryTestFactory;
import org.openmetadata.it.factories.UserTestFactory;
import org.openmetadata.it.util.NamespaceCleanup;
import org.openmetadata.it.util.RelationshipTypeTestSupport;
import org.openmetadata.it.util.SdkClients;
import org.openmetadata.it.util.TestNamespace;
import org.openmetadata.it.util.TestNamespaceExtension;
Expand Down Expand Up @@ -116,9 +117,7 @@ public class GlossaryRdfImportIT {
void cleanup(TestNamespace ns) throws Exception {
NamespaceCleanup.deleteRoots(ns.drainTrackedRoots());
customPropertyNames.forEach(this::deleteCustomProperty);
for (UUID id : relationshipTypeIds) {
deleteRelationshipType(id);
}
RelationshipTypeTestSupport.hardDeleteAll(relationshipTypeIds);
}

@ParameterizedTest
Expand Down Expand Up @@ -1026,6 +1025,59 @@ private void assertRelationshipTypeMissing(String name) throws Exception {
assertEquals(404, response.statusCode(), response.body());
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
void importRestoresASoftDeletedInverseFoundByItsPredicate(boolean governedName, TestNamespace ns)
throws Exception {
Glossary glossary = GlossaryTestFactory.createWithName(ns, "glossaryRestore" + governedName);
String forward = relationshipTypeName(glossary.getName());
String inverse = forward + "Inverse";
relationshipTypeIds.add(RelationshipTypeIds.stableId(forward));
relationshipTypeIds.add(RelationshipTypeIds.stableId(inverse));
RelationshipType deleted = softDeletedPartner(glossary, inverse, governedName);
relationshipTypeIds.add(deleted.getId());
String ontology = inverseCycleOntology(glossary.getName(), forward, inverse, "undeclared");

JsonNode planned = importRdfBody(glossary.getName(), ontology, true);

assertTrue(
planned.path("messages").toString().contains(deleted.getName() + "' is deleted"),
planned.toString());
assertTrue(relationshipTypeById(deleted.getId()).path("deleted").asBoolean());

long restoredAfter = System.currentTimeMillis();
JsonNode result = importRdfBody(glossary.getName(), ontology);

assertEquals(3, result.path("relationsAdded").asInt(), result.toString());
assertEquals(planned.path("relationsAdded"), result.path("relationsAdded"));
assertEquals(planned.path("relationTypesRegistered"), result.path("relationTypesRegistered"));
JsonNode restored = getRelationshipType(deleted.getName());
assertEquals(deleted.getId().toString(), restored.path("id").asText());
assertFalse(restored.path("deleted").asBoolean());
if (governedName) {
assertEquals(
404,
get(SdkClients.getServerUrl() + "/v1/relationshipTypes/name/" + inverse).statusCode(),
"no alias is registered beside the governed type");
}
assertInversePair(forward, deleted.getName());
assertCyclePerspectives(glossary, forward, deleted.getName());
assertTrue(
restoreEventsSince(deleted.getId(), restoredAfter), "the restore is recorded as an event");
}

private boolean restoreEventsSince(UUID id, long timestamp) {
RelationshipTypeTestSupport.Reply reply =
RelationshipTypeTestSupport.send(
"GET", "/v1/events?entityRestored=relationshipType&timestamp=" + timestamp, null);
assertEquals(200, reply.status(), reply.message());
boolean found = false;
for (JsonNode event : reply.body().path("data")) {
found |= id.toString().equals(event.path("entityId").asText());
}
return found;
}

@Test
void importPreservesSymmetricSelfInverseWhenNamedInverseIsDeclared(TestNamespace ns)
throws Exception {
Expand Down Expand Up @@ -1072,6 +1124,106 @@ void importPreservesSymmetricSelfInverseWhenNamedInverseIsDeclared(TestNamespace
}
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
void importSkipsANameHeldByADeletedTypeOnAnotherPredicate(boolean dryRun, TestNamespace ns)
throws Exception {
Glossary glossary = GlossaryTestFactory.createWithName(ns, "glossaryNameHeld" + dryRun);
String authored = relationshipTypeName(glossary.getName());
relationshipTypeIds.add(RelationshipTypeIds.stableId(authored));
URI oldPredicate = URI.create("http://example.com/elsewhere/" + glossary.getName() + "#old");
RelationshipType held =
SdkClients.adminClient()
.relationshipTypes()
.create(
new CreateRelationshipType()
.withName(authored)
.withDisplayName("Held name")
.withDescription("Governed on another predicate")
.withRdfPredicate(oldPredicate)
.withCategory(RelationshipTypeCategory.CUSTOM)
.withPaletteKey(RelationshipPaletteKey.BLUE));
relationshipTypeIds.add(held.getId());
assertEquals(200, RelationshipTypeTestSupport.deleteType(held.getId(), false).status());

JsonNode result =
importRdfBody(
glossary.getName(),
inverseCycleOntology(glossary.getName(), authored, "unused", "none"),
dryRun);

assertTrue(
result
.path("messages")
.toString()
.contains("held by a deleted relationship type on " + oldPredicate),
result.toString());
assertTrue(
result
.path("messages")
.toString()
.contains("its relationship type '" + authored + "' was skipped as invalid"),
result.toString());
assertEquals(0, result.path("relationTypesRegistered").asInt(), result.toString());
assertEquals(0, result.path("relationsAdded").asInt(), result.toString());
JsonNode stored = relationshipTypeById(held.getId());
assertTrue(stored.path("deleted").asBoolean(), stored.toString());
assertEquals(oldPredicate.toString(), stored.path("rdfPredicate").asText());
}

/**
* A soft-deleted type on the predicate the ontology names {@code name}: one an earlier import
* registered under that name, or a governed type whose name differs from the IRI's local name.
*/
private RelationshipType softDeletedPartner(Glossary glossary, String name, boolean governedName)
throws Exception {
RelationshipType type;
if (governedName) {
type =
SdkClients.adminClient()
.relationshipTypes()
.create(
new CreateRelationshipType()
.withName(name + "Governed")
.withDisplayName("Governed inverse")
.withDescription("Governed under its own name")
.withRdfPredicate(
URI.create(
"http://example.com/ontology/" + glossary.getName() + "#" + name))
.withCategory(RelationshipTypeCategory.CUSTOM)
.withPaletteKey(RelationshipPaletteKey.BLUE));
} else {
importRdfBody(
glossary.getName(),
inverseCycleOntology(glossary.getName(), name, "unused", "none")
.replace("hcp:Term", "hcp:Earlier"));
for (int index = 0; index < 3; index++) {
RelationshipTypeTestSupport.Reply deleted =
RelationshipTypeTestSupport.send(
"DELETE",
"/v1/glossaryTerms/name/"
+ glossary.getName()
+ ".Earlier"
+ index
+ "?hardDelete=true",
null);
assertEquals(200, deleted.status(), deleted.message());
}
type = RelationshipTypeTestSupport.asType(RelationshipTypeTestSupport.getTypeByName(name));
}
RelationshipTypeTestSupport.Reply reply =
RelationshipTypeTestSupport.deleteType(type.getId(), false);
assertEquals(200, reply.status(), reply.message());
return type;
}

private JsonNode relationshipTypeById(UUID id) throws Exception {
HttpResponse<String> response =
get(SdkClients.getServerUrl() + "/v1/relationshipTypes/" + id + "?include=all");
assertEquals(200, response.statusCode(), response.body());
return OBJECT_MAPPER.readTree(response.body());
}

@Test
void importKeepsNamedPartnerEdgesWhenInverseIsSymmetric(TestNamespace ns) throws Exception {
Glossary glossary = GlossaryTestFactory.createWithName(ns, "glossarySymmetricPartner");
Expand Down Expand Up @@ -1222,20 +1374,6 @@ private String relationshipTypeName(String glossaryName) {
return "prescribes" + RelationshipTypeIds.stableId(glossaryName).toString().replace("-", "");
}

private void deleteRelationshipType(UUID id) throws Exception {
HttpRequest request =
HttpRequest.newBuilder()
.uri(
URI.create(
SdkClients.getServerUrl() + "/v1/relationshipTypes/" + id + "?hardDelete=true"))
.header("Authorization", "Bearer " + SdkClients.getAdminToken())
.timeout(Duration.ofSeconds(30))
.DELETE()
.build();
HttpResponse<String> response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
assertTrue(response.statusCode() == 200 || response.statusCode() == 404, response.body());
}

private HttpResponse<String> sendImportRdf(
String glossaryName, String token, String body, boolean dryRun) throws Exception {
String url =
Expand Down
Loading
Loading