Skip to content

Fix #427: improvmenet on assignOwnership mechanisms - #435

Merged
antoineatsoprasteria merged 2 commits into
developmentfrom
427-assignownership-duplicates-the-member-when-an-owning-membership-is-re-assigned-no-public-way-to-reorder-or-remove-owned-relationships
Nov 12, 2026
Merged

antoineatsoprasteria merged 2 commits into
developmentfrom
427-assignownership-duplicates-the-member-when-an-owning-membership-is-re-assigned-no-public-way-to-reorder-or-remove-owned-relationships

Conversation

@antoineatsoprasteria

Copy link
Copy Markdown
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the SysML2.NET code style guidelines
  • I have provided test coverage for my change (where applicable)

Description

Fix #427

Extension method to allow removal and re-ordering in the 2 composite collection. Ensure uniqueness and fix assembler synchronization

@samatstariongroup samatstariongroup left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The build is clean and all 1502 tests pass locally. Please address the following before merge.

1. Three-argument AssignOwnership refuses some valid moves as a "containment cycle"

SysML2.NET/Extensions/ElementExtensions.cs:64 (the check is at line 393)

AssertCanOwnRelatedElement(bridgeRelationship, target) calls AssertCanContain, which runs IsContainedTransitivelyBy(relationship, element) against the relationship's current owner chain. This overload moves the relationship under source before it attaches target, so the current chain is the wrong one to check.

Failure: T currently owns relationship R (an Annotation, say, or a FeatureMembership that owns nothing yet). S.AssignOwnership(R, T) throws "Containment cycle", although the result S → R → T contains no cycle. The real cycles are already caught by the source == target, IsContainedTransitivelyBy(source, target) and IsContainedTransitivelyBy(source, relationship) checks.

Fix: skip the relationship-chain cycle check on this path. Either split AssertCanContain into a type/self check and a cycle check, or pass a flag. Add a test case in ElementExtensionsTestFixture: T owns R, then S.AssignOwnership(R, T) succeeds.

2. Syncing an owned list is O(n²) even when nothing changed

SysML2.NET/Extensions/ElementExtensions.cs:500-513

For every child, Attach calls ownedList.IndexOf(child), a linear search when the child is already in the list, followed by Move (RemoveAt + Insert). The assembler runs this for every DTO's OwnedRelationship on every Synchronize, so a namespace with thousands of members costs about n²/2 comparisons per DTO even when nothing was reordered.

Fix: skip children that are already in place, e.g.

if (childIndex < ownedList.Count && ReferenceEquals(ownedList[childIndex], children[childIndex]))
{
    continue;
}

3. Synchronize(dtos) changes behaviour, and IAssembler gains a member

SysML2.NET.Dal/Assembler.cs:58, SysML2.NET.Dal/IAssembler.cs:44

Elements that a DTO stops listing as owned used to be removed from Cache. They now stay cached, detached from their owner, and only identifiers passed to the new deletedIdentifiers overload are removed. This fits the API's "a change without a payload means delete" model and is documented in the XML doc, but external callers will not notice the change. The new member on IAssembler also breaks anyone who implements that interface outside the repository.

Fix: state both breaking changes in the PR description and the release notes.

4. Assembler.DetachFromOwner duplicates the core helper and is less defensive

SysML2.NET.Dal/Assembler.cs:178

It calls the public RemoveOwnedRelatedElement / RemoveOwnedRelationship. These throw InvalidOperationException when the back-pointer is set but the item is missing from the owner's list, whereas the private ElementExtensions.DetachFromOwner clears the pointer in that case.

Fix: make ElementExtensions.DetachFromOwner internal (the Dal already has InternalsVisibleTo) and call it from the assembler, so the two cannot drift apart.

…Membership and Annotation at one owned element
@sonarqubecloud

Copy link
Copy Markdown

@antoineatsoprasteria
antoineatsoprasteria merged commit 0feded7 into development Nov 12, 2026
8 checks passed
@antoineatsoprasteria
antoineatsoprasteria deleted the 427-assignownership-duplicates-the-member-when-an-owning-membership-is-re-assigned-no-public-way-to-reorder-or-remove-owned-relationships branch November 12, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AssignOwnership duplicates the member when an owning membership is re-assigned; no public way to reorder or remove owned relationships

2 participants