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

What is the purpose of call to queryOptions.Validate #133

Open
iant-ee opened this issue Jun 23, 2020 · 1 comment
Open

What is the purpose of call to queryOptions.Validate #133

iant-ee opened this issue Jun 23, 2020 · 1 comment

Comments

@iant-ee
Copy link

iant-ee commented Jun 23, 2020

I am comparing the controllers at https://github.com/OData/ODataSamples/tree/master/WebApiClassic/ODataModelReferenceSample/SampleService1/Controllers

OrdersController includes this method:

        public IHttpActionResult GetOrders(ODataQueryOptions<Order> queryOptions)
        {
            return Ok(new List<Order> { _someOrder });
        }

The equivalent method on ProductsController has some additional lines for validation:

        public IHttpActionResult GetProducts(ODataQueryOptions<Product> queryOptions)
        {
            // validate the query.
            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return BadRequest(ex.Message);
            }

            // return Ok<IEnumerable<Product>>(products);
            return StatusCode(HttpStatusCode.NotImplemented);
        }

What is the purpose of the additional lines?

I am intermittently getting the error message "The property 'Foo' cannot be used in the $expand query option", even though I have an [Expand("Foo")] attribute on my Dto. I think the problem occurs when multiple requests to different end points are being processed at the same time. Removing the call to Validate seems to solve the problem (and still gives me a validation error if I try to expand an invalid property), but I want be sure I'm not missing anything.

@iant-ee
Copy link
Author

iant-ee commented Jun 23, 2020

Removing the code doesn't seem to have solved my problem, which looks to be a bug in the library (see accepted answer to https://stackoverflow.com/questions/39515218/odata-error-the-query-specified-in-the-uri-is-not-valid-the-property-cannot-be specifically the section titled "Edit February 2017").

It's still unclear what the benefits are of calling this validation manually, if it gets called by the framework anyway.

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

No branches or pull requests

1 participant