PostgreSQL SMALLINT[] mapping fails in Dapper 2.1.86 but works in 2.1.79
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
PostgreSQL SMALLINT[] mapping fails in Dapper 2.1.86 but works in Dapper 2.1.79.
Environment
- .NET 10
- PostgreSQL
- Npgsql
- Dapper 2.1.86
Database
CREATE TABLE auto_numbers
(
item_name TEXT NOT NULL,
auto_column_name TEXT NOT NULL,
separator_positions SMALLINT[] NOT NULL DEFAULT ARRAY[]::SMALLINT[],
PRIMARY KEY (item_name, auto_column_name)
);
Example value:
INSERT INTO auto_numbers
(item_name, auto_column_name, separator_positions)
VALUES
('queue_visits', 'token_no', ARRAY[1]::SMALLINT[]);
Model
public sealed record AutoNumberRequest
{
public required string ItemName { get; init; }
public required string AutoColumnName { get; init; }
public required IReadOnlyList<short> SeparatorPositions { get; init; } = [];
}
Query
const string sql = """
SELECT
item_name "ItemName",
auto_column_name "AutoColumnName",
separator_positions "SeparatorPositions"
FROM auto_numbers
WHERE item_name = @ItemName
AND auto_column_name = @AutoColumnName
""";
var result = await connection.QuerySingleAsync<AutoNumberRequest>(
sql,
new
{
ItemName = "queue_visits",
AutoColumnName = "token_no"
});
Error with Dapper 2.1.86
System.Data.DataException:
Error parsing column 2 (SeparatorPositions=System.Int16[] - Int16[])
System.InvalidCastException:
Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
...
Npgsql returns the PostgreSQL SMALLINT[] value as System.Int16[].
Version comparison
With Dapper 2.1.79:
<PackageReference Include="Dapper" Version="[2.1.79]" />
the same query and model work correctly.
With Dapper 2.1.86:
<PackageReference Include="Dapper" Version="[2.1.86]" />
the query fails with the exception above.
I also tested changing the property from:
IReadOnlyList<short>
to:
short[]
and short[] also fails with Dapper 2.1.86.
No other application or database changes were made between the tests.
This appears to be a regression in Dapper 2.1.86 when reading PostgreSQL SMALLINT[] values through Npgsql.
Dapper 2.1.79 continues to work correctly with the same PostgreSQL database, Npgsql setup, query, and model.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the SMALLINT[] query with Npgsql and Dapper 2.1.86 using the AutoNumberRequest model and QuerySingleAsync call shown in the issue, then compare it with 2.1.79. Trace the column-mapping path for the System.Int16[] value; done means the query maps SeparatorPositions successfully without the IConvertible exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100