question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test: FromSql error handling not compatible with TypedRelationalValueBufferFactoryFactory

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
divegacommented, Feb 3, 2017

Reopening then. Thanks for letting us know @roji!

0reactions
smitpatelcommented, Apr 14, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework Core FromSql mock test cases
Code is working fine. But I need to write mock test cases. Can anyone help me out? How to mock Context.Query or how...
Read more >
RelationalQueryableExtensions.FromSql Method
Creates a LINQ query based on an interpolated string representing a SQL query.
Read more >
Microsoft.EntityFrameworkCore.Relational.xml 0.41.0
Ensures that the given type name is a valid type for the relational database. An exception is thrown if it is not a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found