CSHARP-5816: Insonsistent behavior of EnsureNoMemberMapConflicts for discriminator convention#1991
CSHARP-5816: Insonsistent behavior of EnsureNoMemberMapConflicts for discriminator convention#1991papafe wants to merge 2 commits into
EnsureNoMemberMapConflicts for discriminator convention#1991Conversation
There was a problem hiding this comment.
Pull request overview
Fixes CSHARP-5816 by making BsonClassMap.GetDiscriminatorConvention() behave consistently when the discriminator element name conflicts with an existing member mapping, and adds a regression test to prevent reintroducing the issue.
Changes:
- Update
BsonClassMap.GetDiscriminatorConvention()to cache the discriminator convention only after conflict validation succeeds. - Add a unit test that asserts repeated calls to
GetDiscriminatorConvention()consistently throw when a member uses the discriminator element name.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/MongoDB.Bson/Serialization/BsonClassMap.cs |
Moves discriminator convention caching to occur after EnsureNoMemberMapConflicts validation passes. |
tests/MongoDB.Bson.Tests/Serialization/BsonClassMapTests.cs |
Adds a regression test covering repeated GetDiscriminatorConvention() calls when a member conflicts with the discriminator element name. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| public string ElementName => "type"; | ||
| public Type GetActualType(IBsonReader bsonReader, Type nominalType) => nominalType; | ||
| public BsonValue GetDiscriminator(Type nominalType, Type actualType) => nominalType.Name; |
Claude reviewThis is the output from running the review-areas skill being worked on in #1993
PR summaryDescription: This PR touches Assessment: The problem is real and the diff confirms it clearly: the original code assigned before validating, so the second call hit the early-return Verdict: looks good Summary5 reviewers ran (1 area + 3 cross-cutting + 1 PR summary). 4 approved, 1 flagged, 0 escalated. (PR-summary verdict is not counted in those totals.) EscalationsNone. Cross-cutting findings
Area findingsbson-reviewer —
Tests run (by bson-reviewer):
Unmapped changes
|
| EnsureNoMemberMapConflicts(discriminatorConvention.ElementName); | ||
| } | ||
|
|
||
| // only cache if validation succeeds |
There was a problem hiding this comment.
Claude: When LookupDiscriminatorConvention() returns null, the new code assigns null back to _discriminatorConvention, so no caching of the null result occurs and every call re-runs the lookup walk — this is pre-existing behavior preserved by the fix, not a regression, but the comment "only cache if validation succeeds" is slightly misleading since caching null is also suppressed; consider guarding the null case separately (e.g. a dedicated sentinel or a bool _discriminatorConventionResolved flag) if the repeated lookup ever becomes a performance concern in hot paths.
There was a problem hiding this comment.
Reasonable comment, but I wanted to do the minimum amount of changes to fix this.
…r discriminator convention
No description provided.