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

Aperta
#4,114 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Sorbitol ci sta già lavorando.

Dal 29/10/2026.

  • #4115 di @Sorbitol — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
csharp, postgresql
Ambito
databases

Direzione di ricerca

Start in src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs, at GetStorageParameters, where non-boolean and non-string values are formatted. Check the migration SQL generator tests for storage parameters and add coverage for a decimal value under a comma-decimal culture. Done means generated CREATE TABLE, CREATE INDEX, and ALTER TABLE storage parameter SQL uses a dot decimal separator; pull request #4115 is already open.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

A non-integer numeric storage parameter (double, float, decimal) is written into DDL with the current culture's decimal separator. Under sv-SE, de-DE, fr-FR and other comma cultures, HasStorageParameter("autovacuum_vacuum_scale_factor", 0.01) generates autovacuum_vacuum_scale_factor=0,01, which breaks CREATE TABLE … WITH (…) and ALTER TABLE … SET (…) (and CREATE INDEX … WITH (…), which shares the same helper): the statement fails with a syntax error.

Model Culture Generated SQL
HasStorageParameter("autovacuum_vacuum_scale_factor", 0.01) en-US …(autovacuum_vacuum_scale_factor=0.01) ✅
same sv-SE …(autovacuum_vacuum_scale_factor=0,01) ❌
Environment
  • PostgreSQL 18.6 (only to confirm the error; the repro itself needs no database)
  • .NET SDK 10.0.403 / runtime 10.0.14, Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3, EF Core 10.0.4, Npgsql 10.0.3
  • Windows 11, current culture sv-SE
Repro
using System.Globalization;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

foreach (var culture in new[] { "en-US", "sv-SE" })
{
    CultureInfo.CurrentCulture = new CultureInfo(culture);
    Console.WriteLine($"--- {culture} ---");

    using var context = new TestContext();
    var generator = context.GetService<IMigrationsSqlGenerator>();
    var differ = context.GetService<IMigrationsModelDiffer>();
    var model = context.GetService<IDesignTimeModel>().Model.GetRelationalModel();

    var operations = differ.GetDifferences(null, model);
    foreach (var command in generator.Generate(operations, context.Model))
        Console.WriteLine(command.CommandText);
}

public class TestContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options.UseNpgsql("Host=unused");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
        => modelBuilder.Entity<Row>().HasStorageParameter("autovacuum_vacuum_scale_factor", 0.01);
}

public class Row
{
    public int Id { get; set; }
}

Output (Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3):

--- en-US ---
CREATE TABLE "Row" (
    "Id" integer GENERATED BY DEFAULT AS IDENTITY,
    CONSTRAINT "PK_Row" PRIMARY KEY ("Id")
)
WITH (autovacuum_vacuum_scale_factor=0.01);

--- sv-SE ---
CREATE TABLE "Row" (
    "Id" integer GENERATED BY DEFAULT AS IDENTITY,
    CONSTRAINT "PK_Row" PRIMARY KEY ("Id")
)
WITH (autovacuum_vacuum_scale_factor=0,01);

Diffing a model with 0.2 against one with 0.01 gives, under sv-SE: ALTER TABLE "Row" SET (autovacuum_vacuum_scale_factor=0,01); (en-US: =0.01). de-DE and fr-FR produce the same 0,01.

PostgreSQL 18 rejects the sv-SE statement:

ERROR:  syntax error at or near "01"
LINE 5: WITH (autovacuum_vacuum_scale_factor=0,01);
                                               ^
Source reference

GetStorageParameters formats every value other than bool and string with a plain ToString():

https://github.com/npgsql/efcore.pg/blob/cd8b7f9ac6e37deb2bd7ea18d318b6c25fd1b5c1/src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs#L2280-L2290

Its result is used by WITH (…) (emitted for both CREATE TABLE and CREATE INDEX) and by ALTER TABLE … SET (…), while other numeric DDL in the same file already uses CultureInfo.InvariantCulture (RESTART WITH, INCREMENT BY). A likely fix is Convert.ToString(a.Value, CultureInfo.InvariantCulture)! on line 2289.

(Links are to main; the code is identical in v10.0.3, L2066–L2075, and still present on hotfix/10.0.4.)

Similar to #787 (invariant culture for DateTime literals).

Workaround: pass the value as a string ("0.01"), which the generator quotes and PostgreSQL accepts.

Lingua principale
C#
Stelle
1.8k
Fork
268
Merge medio
2h 35m
PR unite (30g)
136

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di npgsql/efcore.pg

Tutte le issue di npgsql/efcore.pg

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.