[release/10.0] Fix for persisting null optional complex property with default values#37952
Conversation
…property with default values Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Ports a fix into release/10.0 for snapshot change tracking of optional complex properties when transitioning from non-null (with all default-valued inner properties) to null, ensuring the null is detected and persisted, with an AppContext quirk switch to restore the previous behavior if needed.
Changes:
- Update
ChangeDetector.DetectComplexPropertyChangeto mark inner complex properties modified on both null→non-null and non-null→null transitions (with opt-out quirk switch). - Add a new specification test covering non-null(defaults)→null persistence for an optional multi-property complex type.
- Skip the new test for providers/configurations where it’s not supported (InMemory; SqlServer proxies/notification tracking).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/EFCore/ChangeTracking/Internal/ChangeDetector.cs | Extends complex-property null-transition detection; adds Microsoft.EntityFrameworkCore.Issue37890 quirk switch to restore prior behavior. |
| test/EFCore.Specification.Tests/ComplexTypesTrackingTestBase.cs | Adds coverage for persisting non-null(defaults)→null on an optional complex property with multiple properties. |
| test/EFCore.InMemory.FunctionalTests/ComplexTypesTrackingInMemoryTest.cs | Skips the new test due to existing InMemory complex-type limitations (#31464). |
| test/EFCore.SqlServer.FunctionalTests/ComplexTypesTrackingSqlServerTest.cs | Skips the new test for the proxies/notification tracking variant (#36175). |
You can also share your feedback on Copilot code review. Take the survey.
|
@copilot Update progress using the servicing template from the servicing pr skill |
Updated the PR description to follow the servicing template with all required sections (Description, Customer impact, How found, Regression, Testing, Risk). |
artl93
left a comment
There was a problem hiding this comment.
Approved. New scenario, customer reported.
Port of #37944
Fixes #37890
Description
When optional complex properties transition from non-null to null with default-valued properties, those default values were not being tracked and therefore not set to null in the database. This is the inverse scenario of the fix in #37664.
Customer impact
Silent failure to persist null values leading to data corruption; no workaround known.
How found
3 user reports on 10.0.3
Regression
No. Optional complex properties were introduced in EF 10.
Testing
Test added
Risk
Low — single condition removed; quirk added.