Repository navigation
Format storage parameter values with the invariant culture - #4115
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
roji
left a comment
There was a problem hiding this comment.
Recommendation: Keep the one-line product fix and simplify the regression test using EF's existing culture attribute. I found no blocking correctness issues.
Problem. This is a real migration-generation bug, not just inconsistent display formatting. For example:
CultureInfo.CurrentCulture = new CultureInfo("de-DE");
modelBuilder.Entity<Row>()
.HasStorageParameter("autovacuum_vacuum_scale_factor", 0.01);The original implementation emits autovacuum_vacuum_scale_factor=0,01; PostgreSQL rejects it with SQLSTATE 42601.
Expected approach / upstream alignment. Format numeric storage parameters invariantly in the existing shared helper. I checked the exact EF revision corresponding to this PR's pinned packages, f05a97f: relational SQL literals and SQL Server migration numeric constants use invariant formatting. EF has no direct equivalent of PostgreSQL storage parameters; matching the formatting behavior does not require introducing a new abstraction or type-mapping pipeline here.
Assessment. Convert.ToString(value, CultureInfo.InvariantCulture) matches that behavior for the affected numeric types. The shared helper covers table creation, index creation, and table alterations, while preserving the existing bool/string branches. Public signatures and model/snapshot representations remain unchanged; this corrects generated DDL without requiring a data/config migration or conceptual documentation changes.
Gap / simplification. The added test is valid, but its manual culture cloning and restoration duplicate EF's UseCultureAttribute. The inline comment proposes a smaller upstream-aligned regression test. This is nonblocking, not a defect in the fix.
Manual validation. Using the exact pinned SDK/EF packages, I wrote a standalone consumer against the published package built from the PR's base commit and then the actual PR source. I generated and executed DDL against isolated PostgreSQL 18 containers under en-US, sv-SE, de-DE, and fr-FR, covering double/float/decimal table creation and alterations, plus model-generated table/index creation and unchanged bool/string/integer formatting. The base reproduced 42601 in comma cultures; the PR succeeded throughout. The original focused tests also passed. Separately, I tried the smaller [UseCulture("de-DE")] test in a scratch copy: it passed with the fix and failed with 42601 when the fix was removed.
Posted by copilot
| [Fact] | ||
| public virtual async Task Create_table_with_storage_parameter_is_culture_invariant() | ||
| { | ||
| var originalCulture = CultureInfo.CurrentCulture; |
There was a problem hiding this comment.
Could we use EF's [UseCulture("de-DE")] instead of cloning the culture and manually restoring it? The attribute is present in the pinned EF version and its namespace is already imported by test/Directory.Build.props. Upstream uses it for culture-sensitive regression tests, for example MigrationsIdGeneratorTest.
We can also add this numeric parameter and its scaffolded-value assertion to the existing Create_table_with_storage_parameter test and put the attribute there, avoiding the duplicated table setup. I verified that consolidated version passes with the fix and fails with PostgreSQL 42601 without it. Nonblocking simplification; the product change looks correct.
Posted by copilot
roji
left a comment
There was a problem hiding this comment.
Thank you, LGTM. Will simplify the test slightly.
Use the upstream UseCulture attribute and extend the existing storage parameter test instead of duplicating its setup. Co-authored-by: Copilot App <[email protected]>
Backport #4115, including its simplified culture regression test. Co-authored-by: Copilot App <[email protected]>
) Backport #4115, including its simplified culture regression test. Co-authored-by: Copilot App <[email protected]>
GetStorageParametersformatted non-bool, non-stringvalues withToString(), so adoublesuch asHasStorageParameter("autovacuum_vacuum_scale_factor", 0.01)became0,01under comma-decimal cultures and brokeCREATE TABLE … WITH (…),CREATE INDEX … WITH (…)andALTER TABLE … SET (…). It now usesConvert.ToString(value, CultureInfo.InvariantCulture), as the sequence DDL in the same file already does.Test:
Create_table_with_storage_parameter_is_culture_invariantinMigrationsNpgsqlTestcreates a table with that parameter under a culture whose decimal separator is,, and asserts the generated SQL and the scaffolded value. Without the fix it fails with42601: syntax error at or near "01". TheALTER TABLEpath goes through the same helper.Ran locally with the pinned SDK (11.0.100-rc.3.26522.148) against postgis/postgis:18-3.6:
MigrationsNpgsqlTestandMigrationsInfrastructureNpgsqlTest: 280 passed, 2 skipped;EFCore.PG.Tests: 770 passed;dotnet format --verify-no-changeson the changed files: clean.Fixes #4114
🤖 Generated with Claude Code