Skip to content

MessagePack: Fix client serialization for multiple levels of inheritance - #595

Merged
Daniel-Svensson merged 5 commits into
OpenRIAServices:mainfrom
Daniel-Svensson:messagpack2
Jul 30, 2026
Merged

MessagePack: Fix client serialization for multiple levels of inheritance#595
Daniel-Svensson merged 5 commits into
OpenRIAServices:mainfrom
Daniel-Svensson:messagpack2

Conversation

@Daniel-Svensson

@Daniel-Svensson Daniel-Svensson commented Jul 29, 2026

Copy link
Copy Markdown
Member

Fix client handling of classes with multiple levels of inheritance.

Summary by CodeRabbit

  • Bug Fixes

    • Improved MessagePack serialization for entities involved in inheritance hierarchies.
    • Ensured derived-type metadata is consistently applied during serializer construction.
  • Tests

    • Added coverage for querying entities across base, intermediate, and most-derived inheritance levels.
    • Verified results and entity counts across multiple domain contexts.

@Daniel-Svensson
Daniel-Svensson requested a review from Copilot July 29, 2026 18:48
@Daniel-Svensson

Copy link
Copy Markdown
Member Author

FYI @fremo917

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

MessagePack serialization now registers converters for the base Entity type, exposes disabled derived-type unions, and applies both through one factory instance. An asynchronous end-to-end test verifies queries across base, intermediate, and most-derived inheritance levels.

Changes

Inheritance-aware serialization

Layer / File(s) Summary
Serializer inheritance wiring
src/OpenRiaServices.Client.DomainClients.Http/Framework/MessagePack/Converters/ObjectConverterFactory.cs, src/OpenRiaServices.Client.DomainClients.Http/Framework/MessagePackHttpDomainClientFactory.cs
ObjectConverterFactory registers entity converters and creates disabled DerivedTypeUnion values; serializer construction applies the same factory to converter and union configuration.
Inheritance query validation
src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs
The asynchronous test loads base, intermediate, and most-derived queries and verifies their entity counts and derived-type results.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MessagePackHttpDomainClientFactory
  participant ObjectConverterFactory
  participant MessagePackSerializer
  participant InheritanceTests
  MessagePackHttpDomainClientFactory->>ObjectConverterFactory: create and register converters
  ObjectConverterFactory-->>MessagePackHttpDomainClientFactory: provide disabled derived-type unions
  MessagePackHttpDomainClientFactory->>MessagePackSerializer: configure converters and unions
  InheritanceTests->>MessagePackSerializer: load inheritance queries
  MessagePackSerializer-->>InheritanceTests: return base and derived entities
Loading

Poem

I’m a rabbit with converters bright,
Unions hop through serializer light.
Base and derived now share the way,
Three little queries bloom today.
Squeak, test, and spring away!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing MessagePack client serialization for multi-level inheritance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/MessagePackWorkarounds.md`:
- Around line 53-56: Replace the placeholder bullet under “PolyType errors give
poor exception messages” with a concrete, usable reference to the relevant
TypeScript PolyType issue or documentation, including its link; if no valid
reference exists, remove the bullet.

In
`@src/OpenRiaServices.Client.DomainClients.Http/Framework/MessagePackHttpDomainClientFactory.cs`:
- Around line 48-52: Update the serializer construction in the MessagePack HTTP
domain client factory to deduplicate DerivedTypeUnions by BaseType before
combining the converter factory unions with the caller-provided serializer
unions, ensuring the converter factory entry overrides matching existing entries
without duplicate keys. Add a regression test using a serializer that already
defines an explicit union and verify construction succeeds with the intended
union applied.

In `@src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs`:
- Around line 400-401: Update the comment above the query test to describe that
the method loads three queries and verifies their entity counts; remove the
inheritance/custom-method description copied from the preceding test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 771e1a61-800a-4d9a-8dce-b34e8e17d019

📥 Commits

Reviewing files that changed from the base of the PR and between 56e27e0 and 0f273b9.

📒 Files selected for processing (4)
  • src/MessagePackWorkarounds.md
  • src/OpenRiaServices.Client.DomainClients.Http/Framework/MessagePack/Converters/ObjectConverterFactory.cs
  • src/OpenRiaServices.Client.DomainClients.Http/Framework/MessagePackHttpDomainClientFactory.cs
  • src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs

Comment thread src/MessagePackWorkarounds.md Outdated
Comment thread src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs Outdated

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.

🟡 Not ready to approve

There are several objective naming/documentation issues (including typos and misleading comments) that should be corrected before merging to keep tests and workaround docs clear and maintainable.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR updates the MessagePack HTTP client serialization configuration to better handle polymorphic entity graphs across multiple inheritance levels, and adds an end-to-end test to validate querying across a 3-level inheritance chain.

Changes:

  • Extend MessagePack serializer configuration to disable built-in derived-type unions for types handled by the custom ObjectConverterFactory.
  • Update ObjectConverterFactory to expose derived-type union configuration required for correct polymorphic handling.
  • Add a new WCF end-to-end async query test covering City -> CityWithEditHistory -> CityWithInfo inheritance.
File summaries
File Description
src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs Adds an async query test to validate client-side deserialization across 3 inheritance levels.
src/OpenRiaServices.Client.DomainClients.Http/Framework/MessagePackHttpDomainClientFactory.cs Updates serializer creation to include derived-type union disabling from ObjectConverterFactory.
src/OpenRiaServices.Client.DomainClients.Http/Framework/MessagePack/Converters/ObjectConverterFactory.cs Adds API to emit derived-type union settings to avoid extra discriminators for affected types.
src/MessagePackWorkarounds.md Updates internal documentation with additional notes about PolyType exception-message quality.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 4
  • Review effort level: Low

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs Outdated
Comment thread src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs Outdated
Comment thread src/MessagePackWorkarounds.md Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs (1)

405-413: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the returned entity types, not only counts.

The middle and most-derived queries only assert that two entities were returned, so incorrect entity types could still pass this test. Add concrete-type assertions, such as checking editResult.Entities.OfType<CityWithInfo>() and mostDerivedResult.Entities.OfType<CityWithInfo>(), to verify inheritance-aware deserialization.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs` around
lines 405 - 413, Extend the assertions in the inheritance test after loading
editResult and mostDerivedResult to verify their entities are concrete
CityWithInfo instances, using OfType<CityWithInfo>() and asserting the expected
count of 2. Keep the existing total-count assertions and baseResult checks
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs`:
- Around line 399-400: Update the inheritance query-test comment near the
hierarchy declaration to read “Ensure we can retrieve entities at all levels of
the hierarchy.” Keep the hierarchy description unchanged.

---

Outside diff comments:
In `@src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs`:
- Around line 405-413: Extend the assertions in the inheritance test after
loading editResult and mostDerivedResult to verify their entities are concrete
CityWithInfo instances, using OfType<CityWithInfo>() and asserting the expected
count of 2. Keep the existing total-count assertions and baseResult checks
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1d35d315-d78a-46d0-9780-9cbeaf300ad2

📥 Commits

Reviewing files that changed from the base of the PR and between 0f273b9 and 225effc.

📒 Files selected for processing (1)
  • src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs

Comment thread src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs

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.

🟢 Ready to approve

Only minor documentation/comment typos were found; the functional changes are targeted and include coverage for the reported inheritance scenario.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Comments suppressed due to low confidence (3)

src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs:409

  • Comment grammar: "should be return" should be "should return" (and reads better with a comma).
            // CityWithEditHistory is abstract so should be return exactly the same number of entities as CityWithInfo

src/OpenRiaServices.Client.DomainClients.Http/Framework/MessagePack/Converters/ObjectConverterFactory.cs:63

  • Typo in XML doc: "Nerdabank.MessagePack" should be "Nerdbank.MessagePack" (project/package name), and "built in" should be hyphenated when used as an adjective.
        /// In order to prevent Nerdabank.MessagePack from creating additional discriminators we must disable the built in inheritance support for the types.

src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/InheritanceTests.cs:400

  • Comment grammar: "Ensure we can methods retrieve" reads like a typo and is hard to parse.

This issue also appears on line 409 of the same file.

            // Ensure we can methods retrieve entities at all levels of the hierarchy
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Low

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@sonarqubecloud

Copy link
Copy Markdown

@Daniel-Svensson
Daniel-Svensson merged commit e623cb1 into OpenRIAServices:main Jul 30, 2026
7 checks passed
@Daniel-Svensson
Daniel-Svensson deleted the messagpack2 branch July 30, 2026 09:21
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.

2 participants