Skip to content

Format storage parameter values with the invariant culture - #4115

Merged
roji merged 2 commits into
npgsql:mainfrom
Sorbitol:fix-storage-parameter-culture
Nov 17, 2026
Merged

roji merged 2 commits into
npgsql:mainfrom
Sorbitol:fix-storage-parameter-culture

Conversation

@Sorbitol

Copy link
Copy Markdown
Contributor

GetStorageParameters formatted non-bool, non-string values with ToString(), so a double such as HasStorageParameter("autovacuum_vacuum_scale_factor", 0.01) became 0,01 under comma-decimal cultures and broke CREATE TABLE … WITH (…), CREATE INDEX … WITH (…) and ALTER TABLE … SET (…). It now uses Convert.ToString(value, CultureInfo.InvariantCulture), as the sequence DDL in the same file already does.

Test: Create_table_with_storage_parameter_is_culture_invariant in MigrationsNpgsqlTest creates 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 with 42601: syntax error at or near "01". The ALTER TABLE path goes through the same helper.

Ran locally with the pinned SDK (11.0.100-rc.3.26522.148) against postgis/postgis:18-3.6:

  • the new test: fails before the fix, passes after;
  • MigrationsNpgsqlTest and MigrationsInfrastructureNpgsqlTest: 280 passed, 2 skipped;
  • EFCore.PG.Tests: 770 passed;
  • dotnet format --verify-no-changes on the changed files: clean.

Fixes #4114

🤖 Generated with Claude Code

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]>
@roji
roji enabled auto-merge (squash) November 17, 2026 14:48
roji added a commit that referenced this pull request Nov 17, 2026
Backport #4115, including its simplified culture regression test.

Co-authored-by: Copilot App <[email protected]>
@roji
roji merged commit a715ff3 into npgsql:main Nov 17, 2026
10 checks passed
roji added a commit that referenced this pull request Nov 17, 2026
)

Backport #4115, including its simplified culture regression test.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Numeric storage parameters are formatted with the current culture, so migrations emit 0,01 instead of 0.01

2 participants