Fix PendingModelChangesWarning for Unicode diacritics (NFC/NFD) on Linux#38197
Fix PendingModelChangesWarning for Unicode diacritics (NFC/NFD) on Linux#38197TomasMoralesBarr wants to merge 3 commits intodotnet:mainfrom
Conversation
Fixes dotnet#38191 On Linux/WSL2, string values with diacritic characters (e.g. 'Café') can be stored in NFD Unicode form, while on Windows they are typically NFC. EF Core's migration differ used ordinal string comparison which considered NFC and NFD as different values, causing a false PendingModelChangesWarning. Fix by normalizing string seed data values to NFC before comparison in DiffData."
There was a problem hiding this comment.
Pull request overview
Fixes false PendingModelChangesWarning on Linux/WSL2 caused by NFC vs NFD Unicode normalization differences when diffing seed data in migrations.
Changes:
- Normalize string seed-data values prior to comparison during
MigrationsModelDiffer.DiffData(). - Add a regression test asserting that NFC and NFD equivalents in seed data produce no migration operations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs | Normalizes string values before comparing seed-data column modifications during diffing. |
| test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs | Adds a test covering NFC vs NFD equivalence for seed-data string values. |
Use NormalizationForm.FormC explicitly instead of relying on the default to make the intent clear to future readers of the code.
There was a problem hiding this comment.
Pull request overview
Addresses false PendingModelChangesWarning on Linux/WSL2 when seed data strings differ only by Unicode normalization form (NFC vs NFD), by normalizing string values prior to comparison in the seed data diff logic.
Changes:
- Normalize string seed values to NFC before equality comparison in
MigrationsModelDiffer.DiffData(). - Add a regression test asserting that canonically equivalent NFC/NFD seed strings produce no migration operations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs | Normalizes string values (NFC) before comparing source/target seed data values. |
| test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs | Adds a regression test covering NFC vs NFD equivalence for seeded string values. |
AndriySvyryd
left a comment
There was a problem hiding this comment.
I agree with @roji that a more robust way of fixing this is by using StringComparison.InvariantCulture in a new comparer returned from
That way it will also benefit the update pipeline.
Fixes #38191
Problem
On Linux/WSL2, string values containing diacritic characters (e.g.
Café)can be saved in NFD Unicode normalization form, while on Windows they are
typically NFC. EF Core's
MigrationsModelDifferused ordinal comparisonwhich treated NFC and NFD as different values, causing a false
PendingModelChangesWarning.Fix
Normalize string values to NFC before comparison in
DiffData().Test
Added
Seed_data_with_NFD_vs_NFC_unicode_string_is_considered_unchangedtoMigrationsModelDifferTestwhich confirms NFC and NFD strings representingthe same character produce no migration diff.