-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Comparing a property with a value converter against null throws exception in EF7 InMemory #29603
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Have this exact problem in some tests. Thanks for the workaround. Is this not going to be fixed until 8? Just want to know how much adjustment I need to do make. Thanks. |
@adamhathcock (and others): make sure to vote (👍) for this issue. In order for us to get approval to patch an issue we have to provide evidence to the powers-that-be that the issue is highly impacting to customers. |
Thanks! I'm not sure how it's not more impactful as it's a common practice to have Memory DB for some testing. I guess it's the magic combination of in-memory usage with a null check that way that might be rarer. Unfortunately, the fix requires me to change the tested code and not tests. |
It is, but it's not reecommend. See Testing EF Core Applications. |
I do full integraiton tests with a real DB as well. Might just switch the in-memory tests to the SQLite in-memory to avoid this too. |
@adamhathcock if you're already doing full integration tests with a real DB, you've gone to the trouble of setting up your test infrastructure and hopefully testing efficiently and in isolation. Assuming that's the case, we recommend considering just doing all your tests against your real database, as you've already gone through that effort and can avoid all the problems associated with both InMemory and SQLite in-memory (e.g. different query results). |
there's a variety of tests for history reasons, this might prompt the need to rewrite the memory ones but we'll see. the full integration tests against mysql in a container are great but not all areas have them yet |
@ajcvickers today while trying to upgrade to .NET 7 and EF Core 7 I encountered this issue. For the moment the only workaround I found was using 8.0.0-preview.1.23111.4 of Microsoft.EntityFrameworkCore.InMemory. |
@jochenjonc We looked into patching this, but the code changes are too extensive to include in a patch release. |
Is there any workaround available? We are currently blocked from upgrading to EF 7 because of this issue. I recognize that the In-Memory Provider isn't intended for testing, but is it not a supported part of Entity Framework? What is the supported use case for the In-Memory Provider? If there isn't one that would warrant patching a significant breaking change like this, perhaps the package should no longer be published. |
@analogrelay Workarounds are:
It's not recommended for any customer use case.
Indeed; that has been considered. Would that be a better solution for you? |
Removing the package or making some clear statement that it's not part of the Entity Framework Core product itself would certainly help clarify things. As it is, while it is listed as not "intended for production" in the docs, the implication is that it's still a part of Entity Framework, and thus covered by the same support expectations. In fact the docs say "The provider is maintained by Microsoft as part of the Entity Framework Core Project." If it is no longer covered by the support expectations of the product, it would be good to clarify that. Removing all of our code using the in memory provider isn't feasible for a while so we'll be remaining on EF Core 6. Thanks for clarifying the support policy here. |
Since upgrading to EF7, unit tests utilizing EF InMemory provider started failing. Upon investigating, I was able to narrow it down to null checks not being handled correctly. Digging into the source code, it looks like changes in #27654 this commit might have caused the regression: 3ad8b2e.
Specifically, in this code: https://github.com/dotnet/efcore/blob/main/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs#L286-L302, the
IsAssignable
checks onleftType
andrightType
do not always guarantee that thenewLeft
andnewRight
can be passed to theReplace
method, as they can be aConstantExpression
withnull
value.You can find the relevant code snippets below, or find the whole reproduction at https://github.com/alitas/ef7-inmemory-converter-null-bug.
Relevant code (Sample from https://learn.microsoft.com/en-us/ef/core/modeling/value-comparers)
Stack trace
Provider and version information
EF Core version: 7.0
Database provider: Microsoft.EntityFrameworkCore.InMemory
Target framework: .NET 6 and 7
The text was updated successfully, but these errors were encountered: