[CSHARP-3140] PartialEvaluator should not evaluate unnecessary clauses for AndAlso, Conditional and OrElse Created: 19/Jun/20 Updated: 28/Oct/23 Resolved: 25/Apr/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq, LINQ3 |
| Affects Version/s: | 2.10.4, 2.11.0-beta2 |
| Fix Version/s: | 2.15.1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Анатолий Крыжановский | Assignee: | Robert Stam |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | triaged | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
.net core 3.1 |
||
| Epic Link: | CSHARP-3615 |
| Description |
|
I found case then LINQ filter fail with exception if one of expression member is null. For example we have orders which bounded to factory (view FactoryId field):
We have current user, each user can be bound to factory or can be system wide (factory = null):
Now i want to get all orders which current user can access to:
In case of system wide user (currentUser.Factory = null) i get exception of type System.Reflection.TargetException: Non-static method requires a target with following stacktrace:
If current user bounded to factory all work fine. i try to rewrite to condition operator:
But with no luck - IIF operator does not work. I create fiddle with sample code that reproduce this behaviour: https://dotnetfiddle.net/iFIkrA |
| Comments |
| Comment by Githook User [ 04/May/22 ] | |||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: | |||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 25/Apr/22 ] | |||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: | |||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 20/Apr/22 ] | |||||||||||||||||||||||||||||||||||||
|
This is a bug (or limitation) in the PartialEvaluator class. It doesn't handle the `||` operator properly. Once it encounters a clause that partially evaluates to `true` it should ignore the remaining clauses and simplify the entire expression to `true`. Similar considerations would apply for the `&&` and `?:` operators.
| |||||||||||||||||||||||||||||||||||||
| Comment by James Kovacs [ 24/Nov/20 ] | |||||||||||||||||||||||||||||||||||||
|
Hi, Alexey, Thank you for your interest in the progress on James | |||||||||||||||||||||||||||||||||||||
| Comment by Alexey N/A [ 24/Nov/20 ] | |||||||||||||||||||||||||||||||||||||
|
@rstam Is this in progress? Can we expect to see this in the next stable version? | |||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 13/Jul/20 ] | |||||||||||||||||||||||||||||||||||||
|
I'm not sure yet how easy this might turn out to fix, and we might not get to it for awhile, but I can offer you a workaround that you can start using right away.
The idea of the workaround is to not even use .Where when currentUser.Factory == null. | |||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 13/Jul/20 ] | |||||||||||||||||||||||||||||||||||||
|
Full sample program to reproduce:
|