Skip to content

fix #424 - #437

Open
antoineatsoprasteria wants to merge 2 commits into
developmentfrom
424-bug-json-round-trip-of-dtos-loses-non-derived-members-redefined-by-a-derived-property-memberelement-membername-source-target
Open

antoineatsoprasteria wants to merge 2 commits into
developmentfrom
424-bug-json-round-trip-of-dtos-loses-non-derived-members-redefined-by-a-derived-property-memberelement-membername-source-target

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 #424

It causes test failure on Messagepack/JSON roundtripping since MessagePack have similar issue (#436)

@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 tests pass locally. The JSON side of the #424 fix holds up. Please address the following before merge.

1. ToDto(includeDerivedProperties: false) now computes derived properties and throws on incomplete POCOs

SysML2.NET.CodeGenerator/HandleBarHelpers/PropertyHelper.cs:1517 (WriteRedefinedToDto) and SysML2.NET.CodeGenerator/Templates/Uml/core-dal-poco-uml-extensions.hbs:249. Example output: SysML2.NET.Dal/Core/AutoGenPocoExtension/OwningMembershipExtensions.cs:196-205.

The new lines that copy the redefined members are emitted outside the if (includeDerivedProperties) block, for example:

((IMembership)dto).MemberElement = ((POCO.IMembership)poco).MemberElement.Id;

On the POCO these getters resolve to derived Compute* methods:

  • IMembership.MemberElement → ownedMemberElement → ComputeOwnedMemberElement → OwnedRelatedElement.SingleStrict<IElement>
  • IRelationship.Source → membershipOwningNamespace → ComputeMembershipOwningNamespace, which throws IncompleteModelException when there is no owning INamespace
  • MemberName → ownedMemberElement.name
  • ReferenceSubsetting.SubsettingFeature → referencingFeature, which throws IncompleteModelException
  • IsVariable → mayTimeVary (47 classes)

Failure: new OwningMembership { Id = … }.ToDto() did not throw before this PR and now throws IncompleteModelException. The same applies to any Membership subclass or ReferenceSubsetting that is not attached yet. Converting a partly assembled graph, or exporting a subset, therefore fails in the mode that is meant to skip derivation. It also adds derivation cost to every ToDto(false) call.

Fix: in WriteRedefinedToDto, check property.QueryRedefinitionChainEnd(class). When the chain end is derived, emit the line inside the includeDerivedProperties block (where the same storage may already be set), or emit a guarded read.

Test: nothing covers the Dal side today; the only Dal ToDto test uses AnnotatingElement, which this change does not affect. Add VerifyToDto in a new SysML2.NET.Dal.Tests/OwningMembershipExtensionsTestFixture.cs:

  • an incomplete OwningMembership must convert as intended (not throw with includeDerivedProperties: false);
  • a complete one (Namespace → OwningMembership → named element) must carry MemberElement, MemberName, Source and Target;
  • a PartUsage case showing IsVariable is copied from mayTimeVary.

2. The [Ignore] disables the only Core MessagePack round-trip test

SysML2.NET.Serializer.MessagePack.Tests/SerializerTestFixture.cs:41

Verify_that_iData_from_sysml2_core_json_can_be_deserialized is the only Core MessagePack round-trip check (PsmSerializerTestFixture covers PSM only). Ignoring all of it means a MessagePack regression in any member, not only the members tracked in #436, goes unnoticed until #436 is fixed.

Fix (either):

  • fix #436 in this PR; the formatter is generated, so the same chain-end logic applies; or
  • keep the test running and leave only the known #436 members out of the comparison.

@sonarqubecloud

Copy link
Copy Markdown

@antoineatsoprasteria

Copy link
Copy Markdown
Collaborator Author

@samatstariongroup I decided to follow, for now, the evidence provided by this sentence, written in the SysML 2 specificaiton : "The property mayTimeVary redefines the KerML property Feature::isVariable, making it derived."
Based on that, any derived (by redefintion) properties has a new property attribute and we discard them in comparer/serializer

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.

[Bug]: JSON round trip of DTOs loses non-derived members redefined by a derived property (memberElement, memberName, source, target)

2 participants