Wrong error message when a query options is not enabled in the global configuration but enabled in the controller.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Assemblies affected
ASP.NET Core OData 8.x
Describe the bug
Wrong error message when a query options is not enabled in the global configuration but enabled in the controller.
Reproduce steps
Configure services as follows in the Startup class
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddOData(opt =>
{
opt.AddRouteComponents("odata", GetEdmModel()).Count().Expand().Select().OrderBy().SetMaxTop(5); // We don't enable $filter
});
}
Add a controller method
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.Filter)]
public IQueryable<Book> Get()
{
return _db.Books/*.AsQueryable<Book>()*/;
}
Make the request below
GET ~/Books?$filter=Id eq 1
Response
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. The property 'Id' cannot be used in the $filter query option.",
"details": [],
"innererror": {
"message": "The property 'Id' cannot be used in the $filter query option.",
"type": "Microsoft.OData.ODataException",
"stacktrace": " at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.ValidateSingleValuePropertyAccessNode(SingleValuePropertyAccessNode propertyAccessNode, ODataValidationSettings settings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 389\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.ValidateSingleValueNode(SingleValueNode node, ODataValidationSettings settings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 707\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.ValidateQueryNode(QueryNode node, ODataValidationSettings settings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 565\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.ValidateLogicalOperator(BinaryOperatorNode binaryNode, ODataValidationSettings settings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 217\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.ValidateBinaryOperatorNode(BinaryOperatorNode binaryOperatorNode, ODataValidationSettings settings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 183\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.ValidateSingleValueNode(SingleValueNode node, ODataValidationSettings settings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 683\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.ValidateQueryNode(QueryNode node, ODataValidationSettings settings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 565\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.Validate(FilterClause filterClause, ODataValidationSettings settings, IEdmModel model) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 95\r\n at Microsoft.AspNetCore.OData.Query.Validator.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\FilterQueryValidator.cs:line 63\r\n at Microsoft.AspNetCore.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Query\\FilterQueryOption.cs:line 174\r\n at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\Validator\\ODataQueryValidator.cs:line 69\r\n at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\ODataQueryOptions.cs:line 634\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\EnableQueryAttribute.cs:line 707\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext) in C:\\Users\\kemunga\\source\\repos\\AspNetCoreOData\\src\\Microsoft.AspNetCore.OData\\Query\\EnableQueryAttribute.cs:line 167"
}
}
}
I don't think this is the correct error since it focuses on the property being NotFilterable.
The correct exception should be $Filter query option not being allowed.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with EnableQueryAttribute.cs around ValidateQuery and follow the validation path into FilterQueryValidator.cs, using the reproduced configuration and request. Confirm why the property-level error is returned when $filter is disabled globally. Done means the same request reports that the $filter query option is not allowed, with regression coverage for the controller and global settings combination.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100