Skip to content

[release/10.0] Fix for persisting null optional complex property with default values#37952

Merged
AndriySvyryd merged 1 commit intorelease/10.0from
copilot/port-pull-37944-release-10-0
Mar 24, 2026
Merged

[release/10.0] Fix for persisting null optional complex property with default values#37952
AndriySvyryd merged 1 commit intorelease/10.0from
copilot/port-pull-37944-release-10-0

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

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.

…property with default values

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.DetectComplexPropertyChange to 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.

@AndriySvyryd
Copy link
Member

@copilot Update progress using the servicing template from the servicing pr skill

Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@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).

@AndriySvyryd AndriySvyryd marked this pull request as ready for review March 19, 2026 00:41
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner March 19, 2026 00:41
@AndriySvyryd AndriySvyryd changed the title Port fix for null optional complex property with default values to release/10.0 (with quirk switch) [release/10.0] Port fix for null optional complex property with default values to release/10.0 (with quirk switch) Mar 19, 2026
@AndriySvyryd AndriySvyryd changed the title [release/10.0] Port fix for null optional complex property with default values to release/10.0 (with quirk switch) [release/10.0] Fix for persisting null optional complex property with default values Mar 19, 2026
@AndriySvyryd AndriySvyryd requested a review from artl93 March 19, 2026 01:00
Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

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

Approved. New scenario, customer reported.

@AndriySvyryd AndriySvyryd added this to the 10.0.6 milestone Mar 24, 2026
@AndriySvyryd AndriySvyryd merged commit 8ff6140 into release/10.0 Mar 24, 2026
18 of 19 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/port-pull-37944-release-10-0 branch March 24, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants