AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Term ... is not valid in a $select or $expand expression.

Open EliasTaghavi opened this issue 3 years ago • 3 comments

Assemblies affected "Microsoft.AspNetCore.OData" Version="8.0.9" "Microsoft.OData.Core" Version="7.12.1"

Describe the bug everything is fine in debugging but get exception when deploy the app

Request/Response Please share your request Uri, head or the request body Please share your response head, body.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context { "error": { "code": "", "message": "The query specified in the URI is not valid. Term 'Dang,User)' is not valid in a $select or $expand expression.", "details": [], "innererror": { "message": "Term 'Dang,User)' is not valid in a $select or $expand expression.", "type": "Microsoft.OData.ODataException", "stacktrace": " at Microsoft.OData.UriParser.SelectExpandParser.ParseCommaSeparatedSelectList(Func2 ctor, Func1 termParsingFunc)\n at Microsoft.OData.UriParser.SelectExpandParser.ParseSelect()\n at Microsoft.OData.UriParser.SelectExpandSyntacticParser.Parse(String selectClause, String expandClause, IEdmStructuredType parentStructuredType, ODataUriParserConfiguration configuration, ExpandToken& expandTree, SelectToken& selectTree)\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpandImplementation(String select, String expand, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()\n at Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.get_SelectExpandClause()\n at Microsoft.AspNetCore.OData.Query.Validator.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings)\n at Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.Validate(ODataValidationSettings validationSettings)\n at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\n at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)" } } }

EliasTaghavi avatar Aug 11 '22 11:08 EliasTaghavi

I tried to break down your very complex URL:

https://127.0.0.1:5001/odata/doc?
$expand=tenant(
        $select=Name,Surname
    ),
    part(
        $select=Waqf,Number;
        $expand=Waqf(
            $select=Waqef,Village;
            $expand=Waqef(
                $select=Name,Surname
            ),
            Village(
                $select=Name
            )
        )
    ),
    PerExpireRCManager(
        $select=Name,Surname
    ),
    PerExpireHost(
        $select=Name,Surname
    ),
    Shares(
        $expand=User(
            $select=Name,Surname
        );
        $select=Dang,User
    )
&$count=true
&$orderby=Part/Number,Start%20desc
&$skip=0
&$top=5

The only thing of interest I spotted is that you have a lot of "select; expand" pairs, and the last one is a "expand; select" (i.e. inverted compared to the others). If this was me, I'd just try inverting those last 2 as a test. So instead of:

    Shares(
        $expand=User(
            $select=Name,Surname
        );
        $select=Dang,User
    )

I'd do:

    Shares(
        $select=Dang,User;
        $expand=User(
            $select=Name,Surname
        )
    )

Just to see if that changes anything.

Also, I'm assuming that if you remove that section entirely, then the query works? Would be nice if you could provide a minimal query that still reproduces the issue.

julealgon avatar Aug 11 '22 13:08 julealgon

as i mentioned in pervious message everything is fine in debugging session but not in production. i think some of environment variables may differ (like culture or timezone) or maybe there is a problem within "Microsoft.OData.UriParser" my develop setup is mac and deploy the app in a linux container

EliasTaghavi avatar Aug 11 '22 16:08 EliasTaghavi

https://dev.azure.com/affinitiv/Affinitiv.Extensions/_git/Affinitiv.Extensions.Collections.Generic/pullrequest/583

I completely missed that, my bad.

@EliasTaghavi do you know if the production deployment involves any sort of proxy, gateway or load balancer? I assume the issue could be related to encoding in the URL, or even perhaps limiting the URL length.

Do you have any server logs showing you the full request URL being sent?

julealgon avatar Aug 11 '22 18:08 julealgon

at last ... I think i found it although there is a new version of package release and i set the project to use it but it hasn't any effect on my issue but i found these is something wrong with the build engine version 17.0 for .NET Screen Shot 1401-05-25 at 3 18 09 PM didn't work... Screen Shot 1401-05-25 at 3 18 45 PM version 17.2 works great... i ask the hosting service provider to update the build engine i hope this fix the issue

EliasTaghavi avatar Aug 16 '22 10:08 EliasTaghavi

Hi, I'm experiencing the same thing, I'm confused what the fix/resolution was?

broomfn avatar May 24 '23 12:05 broomfn

So, I've tracked down my specific issue, in case this is of any help to anyone else experiencing this:

https://github.com/traefik/traefik/issues/9164

broomfn avatar May 25 '23 16:05 broomfn