HotChocolate.Types.Filters Null Reference issue #7850
Replies: 2 comments 1 reply
-
I've loaded code from GitHub and found kind of easy fix (not sure it will not cause new issues).
to
It works for both filters. |
Beta Was this translation helpful? Give feedback.
-
PR with possible fix (for test repo): olu-lebara/FilterIssueTest#1 |
Beta Was this translation helpful? Give feedback.
-
Hello,
I use GraphQL HotChocolate nuget (HotChocolate.AspNetCore and HotChocolate.Types.Filters) of version 11.0.9 (need to use quite old, but reproduced even in 13.9.14) with enabled filtering capabilities for collections.
In general, filtering works well, but for some queries it causes NullReferenceException during filtering (middleware stage).
Bit details (I've created a small project to reproduce this issue):
And query, which causes the error:
query { items(where: {categories_some: {name: "Cat1"}, itemSetting: {data: 123}}) { id itemSetting { data } categories { name } } }
Error itself:
{ "errors": [ { "message": "Unexpected Execution Error", "locations": [ { "line": 2, "column": 3 } ], "path": [ "items" ], "extensions": { "message": "Object reference not set to an instance of an object.", "stackTrace": " at lambda_method83(Closure, Item)\r\n at System.Linq.Enumerable.WhereEnumerableIterator 1.MoveNext()\r\n at HotChocolate.Execution.Processing.ResolverTask.<>c__DisplayClass13_0.<ExecuteResolverPipelineAsync>b__0()\r\n at System.Threading.Tasks.Task 1.InnerInvoke()\r\n at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)\r\n--- End of stack trace from previous location ---\r\n at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)\r\n--- End of stack trace from previous location ---\r\n at HotChocolate.Execution.Processing.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n at HotChocolate.Execution.Processing.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)" } } ], "data": { "items": null } }
The strange thing is, if I change the order of filter condition, no issue:
items(where: { itemSetting: {data: 123}, categories_some: {name: "Cat1"}})
I've bit investigated, and looks like QueryableFilterVisitor creates Expression for IQueriable with wrong order (first it checks value of Data, and then it checks ItemSetting object is not null).
I have a small project to reproduce this issue if needed (https://github.com/olu-lebara/FilterIssueTest).
Please help to find out any fix. Because workaround to change order is not applicable in my case (clients do not know about this issue).
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions