Conversions to text: a `char` space is lost, `Convert.ToString(bool)` gives `true`, and `string.Join` with a null separator returns NULL
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 80/100
Direção de pesquisa
Start from NpgsqlStringMethodTranslator.cs (lines 217-225, 274-279) and NpgsqlObjectToStringTranslator.cs (102-107) to pad char values with rpad(x,1); in NpgsqlConvertTranslator.cs (36) use a CASE for bool like bool.ToString. Mimic #4001's rpad fix. Run the issue's repro and confirm the generated SQL matches .NET output (space kept, Convert.ToString(bool) gives True, null separator coalesced).
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
| Environment | |
|---|---|
| PostgreSQL | 18.6 (postgres:18), session TimeZone Etc/UTC |
| .NET 10 | runtime 10.0.11, Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3, EF Core 10.0.4 |
| .NET 11 | runtime 11.0.0-rc.2, Npgsql.EntityFrameworkCore.PostgreSQL 11.0.0-rc.2, EF Core 11.0.0-rc.2 |
| Also | Npgsql 10.0.3 on both lines, macOS arm64 |
The first repro prints the same output on both lines; the IndexOf one differs by line, as shown. main at 150011d has the same code.
| LINQ | Row | .NET | PostgreSQL | SQL |
|---|---|---|---|---|
string.Join(sep, r.Tags), char sep = ' ' |
{a,b} |
a b |
ab |
array_to_string(r."Tags", @sep, '') |
r.Text.PadRight(4, sep), char sep = ' ' |
abc |
abc␠ |
abc |
rpad(r."Text", 4, @sep) |
r.Space.ToString() |
char column ' ' |
" " |
"" |
r."Space"::text |
r.Text.IndexOf(r.Space), 10.x only |
a b, ' ' |
1 | 0 | strpos(r."Text", r."Space") - 1 |
Convert.ToString(r.Flag) |
true |
True |
true |
r."Flag"::text |
string.Join(r.Separator, r.Tags) |
separator NULL | ab |
NULL | array_to_string(r."Tags", r."Separator", '') |
Repro
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
await using var context = new TestContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Rows.Add(new Row { Tags = ["a", "b"], Space = ' ', Flag = true, Separator = null, Text = "abc" });
await context.SaveChangesAsync();
var row = await context.Rows.AsNoTracking().SingleAsync();
var sep = ' ';
// 1. A space in character(1) is lost when it becomes text
Console.WriteLine($"string.Join(' ' parameter, Tags): .NET {string.Join(sep, row.Tags)}|, database {await context.Rows.Select(r => string.Join(sep, r.Tags)).SingleAsync()}|");
Console.WriteLine($"Text.PadRight(4, ' ' parameter): .NET {row.Text.PadRight(4, sep)}|, database {await context.Rows.Select(r => r.Text.PadRight(4, sep)).SingleAsync()}|");
Console.WriteLine($"Space.ToString(): .NET {row.Space.ToString()}|, database {await context.Rows.Select(r => r.Space.ToString()).SingleAsync()}|");
// 2. bool to text
Console.WriteLine($"Convert.ToString(Flag): .NET {Convert.ToString(row.Flag)}, database {await context.Rows.Select(r => Convert.ToString(r.Flag)).SingleAsync()}");
// 3. string.Join treats a null separator as ""
Console.WriteLine($"string.Join(null separator, Tags): .NET {string.Join(row.Separator, row.Tags)}, database {await context.Rows.Select(r => string.Join(r.Separator, r.Tags)).SingleAsync() ?? "NULL"}");
public class TestContext : DbContext
{
public DbSet<Row> Rows => Set<Row>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(Environment.GetEnvironmentVariable("Test__Npgsql__DefaultConnection"), o => o.UseNodaTime())
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Row
{
public int Id { get; set; }
public string[] Tags { get; set; } = [];
public char Space { get; set; }
public bool Flag { get; set; }
public string? Separator { get; set; }
public string Text { get; set; } = "";
}
Output (the | marks the end of each value), the same on both lines:
string.Join(' ' parameter, Tags): .NET a b|, database ab|
Text.PadRight(4, ' ' parameter): .NET abc |, database abc|
Space.ToString(): .NET |, database |
Convert.ToString(Flag): .NET True, database true
string.Join(null separator, Tags): .NET ab, database NULL
Repro (`IndexOf` with a char column, 10.x)
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
await using var context = new TestContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Rows.Add(new Row { Text = "a b", Space = ' ' });
await context.SaveChangesAsync();
var row = await context.Rows.AsNoTracking().SingleAsync();
Console.WriteLine($"Text.IndexOf(Space): .NET {row.Text.IndexOf(row.Space)}, database {await context.Rows.Select(r => r.Text.IndexOf(r.Space)).SingleAsync()}");
public class TestContext : DbContext
{
public DbSet<Row> Rows => Set<Row>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(Environment.GetEnvironmentVariable("Test__Npgsql__DefaultConnection"), o => o.UseNodaTime())
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Row
{
public int Id { get; set; }
public string Text { get; set; } = "";
public char Space { get; set; }
}
Output:
.NET 10, 10.0.3: Text.IndexOf(Space): .NET 1, database 0
.NET 11, 11.0.0-rc.2: Text.IndexOf(Space): .NET 1, database 1
charspaces.charcolumns and parameters arecharacter(1), and castingcharacter(n)totextstrips trailing spaces, so' 'becomes''. #4001 handled this forIndexOfonmainby padding withrpad(x, 1). Three places still lose it:string.Join(NpgsqlStringMethodTranslator.cs#L274-L279),PadLeft/PadRight(NpgsqlStringMethodTranslator.cs#L217-L225) andToString()(NpgsqlObjectToStringTranslator.cs#L102-L107). #4001 came with the new char-argument translations and isn't onhotfix/10.0.4, soIndexOf(char column)stays wrong on 10.x.Convert.ToString(bool)is::text(NpgsqlConvertTranslator.cs#L36).bool.ToString()already uses a CASE that givesTrue/False.string.Jointreats a null separator as empty.array_to_string(..., NULL, '')is NULL, soCOALESCE(separator, '')would match.
- Linguagem predominante
- C#
- Estrelas
- 1.8k
- Forks
- 268
- Merge médio
- 2h 35min
- PRs com merge (30d)
- 136
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de npgsql/efcore.pg
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
NTS: the M ordinate is dropped from geometry SQL literals and from geometries stored in JSONTalvez já em andamento @Ahmed7991 assumiu há 6 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
npgsql/efcore.pg#4093 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
`TimeSpan`/`Duration` component members: negative values are floored, and intervals computed in SQL are read field by fieldTalvez já em andamento @jeremy-morren assumiu há 12 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
Numeric storage parameters are formatted with the current culture, so migrations emit 0,01 instead of 0.01Talvez já em andamento @Sorbitol assumiu há 12 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 30/100
Mantenedores costumam responder em até 1 dia
-
`Contains` on a JSON primitive collection compares JSON text, so `DateTime` and `TimeOnly` items never matchTalvez já em andamento @Mr444-dev assumiu há 7 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
npgsql/efcore.pg#4099 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de npgsql/efcore.pg
Issues semelhantes
-
ci-flake kind:tests size:S type:bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 82/100
elsa-workflows/elsa-foundation#4058 · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
games-on-whales/wolf-ui#23 ·
-
SkillsAbertawayfinder:grilling
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
DigiBanks99/lopen#37 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
sebastienros/fluid#1273 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia