ReadItemAsync and bulk execution throwing Bad Request (400) with special characters
See original GitHub issueDescription
When creating a CosmosClient
and setting the option AllowBulkExecution
to true
, the client throws a Bad Request Exception with an empty Reason for specific ID / partitionKey values.
Example id value: NE3cDI8BljAatTkAptI++kPrmDCa+S8j6wBG4Kc7W/A=
To Reproduce
- Create a cosmos db with a container
- Set the id to be the partitionKey
- Create the cosmos client with the options for bulk execution to true
- Read the above id value
var key = "cosmosKey";
var endpoint = "cosmosEndpoint";
var dbName = "dbName";
var containerId = "containerId";
var options = new CosmosClientOptions()
{
AllowBulkExecution = true
};
var client = new CosmosClient(endpoint, key, options);
var container = client.GetContainer(dbName, containerId);
var id = "NE3cDI8BljAatTkAptI++kPrmDCa+S8j6wBG4Kc7W/A=";
var pk = new PartitionKey(id);
try
{
var item = await container.ReadItemAsync<dynamic>(id, pk);
}
catch (Exception ex)
{
}
Expected behavior Error 404 is thrown (Not Found).
Actual behavior Error 400 is thrown (Bad Request), with an empty Reason.
Environment summary SDK Version: 6.0.203 OS Version: windows Microsoft.Azure.Cosmos
- 3.29.0
- 3.29.0-preview
- 3.30.0
- 3.30.0-preview
- 3.30.1
- 3.30.1-preview
Additional context
- When I remove the slash from
NE3cDI8BljAatTkAptI++kPrmDCa+S8j6wBG4Kc7W/A=
, making itNE3cDI8BljAatTkAptI++kPrmDCa+S8j6wBG4Kc7WA=
it does throw a 404 Not Found exception (expected). - When I change
AllowBulkExecution
tofalse
, it also throws a 404 Not Found exception (expected).
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
webservice is throwing 400 Bad request when sending ...
So, what i'm trying to figure out is why the server doesnt like the request when special characters are part of the inputs....
Read more >Troubleshoot Azure Cosmos DB bad request exceptions
In this article. The HTTP status code 400 represents the request contains invalid data or it's missing required parameters.
Read more >How to Fix a 400 Bad Request Error (Causes and Fixes)
URL String Syntax Error. The HTTP error 400 can occur due to incorrectly typed URL, malformed syntax, or a URL that contains illegal...
Read more >400 Bad request - Just getting started
The cause of a 400 error can be a wrongly written URL or a URL that contains unrecognizable characters.
Read more >How to Fix the 400 Bad Request Error (6 Methods)
When you get a 400 Bad Request error, your browser may be unable to load ... Some URLs have special characters, but you'll...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Gotcha, that makes sense. Thank you for your input!
The problem is that because of system design, Create operations send the Ids as part of the body. Read operations use the Id as part of the path/url, that is when the
/
character generates problems.Ideally the service should reject these documents, but that behavior could be interpreted as a breaking change (some customers might be saving data and not using point reads, and it theory works).
But using these characters can lead to failures across different stacks (for example, trying to read those documents in the Portal might also fail).