question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReadItemAsync and bulk execution throwing Bad Request (400) with special characters

See original GitHub issue

Description 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 it NE3cDI8BljAatTkAptI++kPrmDCa+S8j6wBG4Kc7WA= it does throw a 404 Not Found exception (expected).
  • When I change AllowBulkExecution to false, it also throws a 404 Not Found exception (expected).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
silvioguisocommented, Sep 13, 2022

Gotcha, that makes sense. Thank you for your input!

0reactions
ealsurcommented, Sep 13, 2022

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found