Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$filter in $expand can't work if the $expand applied on function results #1162

Open
xuzhg opened this issue May 9, 2018 · 5 comments · May be fixed by #2701
Open

$filter in $expand can't work if the $expand applied on function results #1162

xuzhg opened this issue May 9, 2018 · 5 comments · May be fixed by #2701
Assignees
Labels

Comments

@xuzhg
Copy link
Member

xuzhg commented May 9, 2018

We are seeing an Internal Server Error AGS-side when trying this URL:
https://graph.microsoft.com/v1.0/me/activities/recent?$expand=historyItems($filter=lastModifiedDateTime%20gt%202018-01-22T21:45:00.347Z%20and%20lastModifiedDateTime%20lt%202018-01-22T22:00:00.347Z)

Here’s the error I see in the logs:

[Microsoft.Online.AggregatorService.Common.InternalServerErrorException: Value cannot be null. Parameter name: type;;[System.ArgumentNullException: Value cannot be null. Parameter name: type;
at Microsoft.OData.Edm.EdmTypeSemantics.IsStructured(IEdmTypeReference type)
at Microsoft.OData.UriParser.SelectExpandBinder.BuildNewMetadataBinder(IEdmNavigationSource targetNavigationSource)
at Microsoft.OData.UriParser.SelectExpandBinder.GenerateExpandItem(ExpandTermToken tokenIn)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Microsoft.OData.UriParser.SelectExpandBinder.Bind(ExpandToken tokenIn)
at Microsoft.OData.UriParser.SelectExpandSemanticBinder.Bind(ODataPathInfo odataPathInfo, ExpandToken expandToken, SelectToken selectToken, ODataUriParserConfiguration configuration)
at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()
at Microsoft.Online.AggregatorService.Controller.ParserEngine.<Parse>d__0.MoveNext() in x:\bt\880268\repo\src\dev\Controller\Parser\ParserEngine.cs:line 105 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.Online.AggregatorService.Controller.RequestController.<HandleRequest>d__6.MoveNext() in x:\bt\880268\repo\src\dev\Controller\Controllers\RequestController.cs:line 68;]]

This looks like a bug. The following all work:
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children($expand=children)
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children($select=id)

but these do not:
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children($filter=id eq ‘x’)
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children($orderby=id)

Assemblies affected

  • e.g. OData .Net lib 7.x.*

Additional detail

Optional, details of the root cause if known. Delete this section if you have no additional details to add.

@xuzhg
Copy link
Member Author

xuzhg commented May 9, 2018

I took a quick look the source codes, basically, “delta” is an edm function which returns a collection of entity. But, it doesn’t set the corresponding target navigation source binding.

The returned navigation source is necessary (at least from the source code) to process the nested $filter, $orderby, $search, $compute. But, it’s not necessary to process the nested $select and $expand.

That’s why the following scenarios can work:
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children($expand=children)
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children($select=id)

But, the following scenarios can’t work:
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children($filter=id eq ‘x’)
https://graph.microsoft.com/v1.0/me/drive/root/delta?$expand=microsoft.graph.driveItem/children($orderby=id)

I tested it, if I added the an entity set path (see highlight below) for the delta function, the above failing scenarios can work.

<Function Name=""delta"" IsBound =""true"" EntitySetPath=""bindingParameter/driveItems"">

I think we should take time to investigate why it needs the path in order to resolve the URL.
Thanks

@iriszhou320
Copy link

iriszhou320 commented Mar 13, 2022

@biaol-odata @xuzhg hey any progress or workaround on this? currently we cant use $expand singleExtendedProperties with delta query for messages. thanks!!

@KenitoInc
Copy link
Contributor

I did further digging.
If we don't have an entity set path, the OperationSegment created doesn't have a TargetEdmNavigationSource. This cause the TargetNavigationSource in ODataPathInfo to be null. see

this.targetNavigationSource = lastSegment.TargetEdmNavigationSource;

This cascades to the CreateBindingState method where we return the binding state as null since the TargetNavigationSource is null

private static BindingState CreateBindingState(ODataUriParserConfiguration config,

@habbes
Copy link
Contributor

habbes commented Jul 5, 2023

Why not set an EntitySetPath?

@KenitoInc
Copy link
Contributor

@iriszhou320 Add EntitySetPath to your function e.g

<Function Name=""GetMyDog"" IsBound=""true"" EntitySetPath=""person/MyDog"">
    <Parameter Name=""person"" Type=""Fully.Qualified.Namespace.Person"" />
    <ReturnType Type=""Fully.Qualified.Namespace.Dog"" />
</Function>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants