Really long POST $query results in incomplete JSON response
@xuzhg is already working on this.
Since Aug 6, 2024.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
POSTing a really long $query breaks the JSON output of the response.
Since UseODataQueryRequest does not actually add any endpoints that accept and handle as pure POST, but rather just redirects the POST to the corresponding GET, there is a chance that the query exceeds the server limits and does not work. This, I think, is the cause for this issue
Assemblies affected
Microsoft.AspNetCore.OData 8.2.5
Asp.Versioning.OData 8.1.0
Asp.Versioning.OData.ApiExplorer 8.1.0
Reproduce steps
A recent extreme example I had the misfortune of debugging:
POST /ObservationSites/$query
Body:
$select=name,observationSiteId&$filter=observationSiteId in (<over 7000 ids>)&$top=10&$skip=0&$count=true
Calling the same endpoint with some 3000 ids works as expected.
And yeah, I know the query itself is quite insane, but at least it highlighted this bug 😅
Expected result
- the server would return correctly formatted json
- the logs would not contain the POST body parameters (since it does now, as the query is actually a GET)
Actual result
The JSON response contains the correct data but is malformed:
{"@odata.context":"<metadata>","@odata.count":7087,"value":[
{"observationSiteId":"1","name":"someName"}
//the 9 other queried
}
So the data is fetched, but the json is missing the last ] and }. This happens the same way every time we tried.
And the backend server logs An unhandled exception has occurred while executing the request.
System.UriFormatException: Invalid URI: The Uri string is too long. from the GET endpoint since, well, the request is pretty damn long.
I find it really weird that the data actually gets fetched here, but it does..
Additional detail
I would love to have an option to manually construct a query, so I could define an endpoint e.g.
[EnableQuery]
[HttpPost("$query")]
public IQueryable<Thing> PostQuery(string query){
var opts = new ODataQueryOptions(magically create this from the parameter)
return opts.ApplyTo(things)
}
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.
Assessment
This issue has not been assessed yet.