Test: FromSql error handling not compatible with TypedRelationalValueBufferFactoryFactory
See original GitHub issueThe test Bad_data_error_handling_invalid_cast
fails on Npgsql, which uses TypedRelationalValueBufferFactoryFactory
instead of the default UntypedRelationalValueBufferFactoryFactory
.
First, reading SupplierID
(an integer) as a ProductName
(a string) works, since Npgsql allows reading casting int fields to strings (i.e. when NpgsqlDataReader.GetString()
is called). ProductName
, which is read as SupplierID
, would throw an exception except that in this test it’s a navigation and so is never accessed. It’s sufficient to switch around ProductName
with UnitsInStock
instead and an exception is generated.
However, the error isn’t caught in EntityMaterializerSource.ThrowReadValueException
and rethrown as the proper expected exception, since when TypedRelationalValueBufferFactoryFactory
is used the exception is thrown earlier, when the ValueBuffer is constructed (QueryMethodProvider.cs:42) rather than when it is accessed from the shaper (QueryMethodProvider.cs:48).
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Reopening then. Thanks for letting us know @roji!
@roji - I debugged into this and found out root cause. There are 3 test failures. 2 of them fails with no exception where it is supposed to give exception. I tried with ADO.NET provider for postgre, when we call
NpgSqlDataReader.GetString
regardless of the type of the column, if it can be converted to string (like int type) the conversion will happen. SqlServer is much stricter about this kind of type matching. The tests in question tries to fetch string value from integer column and throws exception for SqlServer. SQLite also allows type conversions internally so we have disabled those tests there. I will update test so that it tries to get integer value from string column which throws exception for PostgreSQL too.There is 3rd test failure which throws different exception message which can be probably the random mix of packages I have accumulated in my machine.