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

System.ArgumentException thrown when calling CreateDatabaseIfNotExistAsync with CosmosClientOption configured with ConsistentPrefix consistency #2196

Closed
IshamMohamed opened this issue Feb 8, 2021 · 4 comments · Fixed by #2198
Labels
bug Something isn't working has-repro Hotfix A hotfix is required for the issue

Comments

@IshamMohamed
Copy link

IshamMohamed commented Feb 8, 2021

The problem exists in: https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.16.0 (the latest version of v3 client) and does not exist in https://www.nuget.org/packages/Azure.Cosmos/4.0.0-preview3 (latest v4 preview client)

Describe the bug
A cosmosdb instance was created in SouthEastAsia region with "Session" default consistency. The following C# code was used to create a DB if not exist:

CosmosClientOptions cosmosClientOptions = new CosmosClientOptions
{
    ConsistencyLevel = ConsistencyLevel.ConsistentPrefix
};
CosmosClient cosmosClient = new CosmosClient(CosmosEndpointUrl, AuthKey, cosmosClientOptions);

DatabaseResponse databaseResponse = await cosmosClient.CreateDatabaseIfNotExistsAsync(DatabaseId);

This throws a System.ArgumentException saying "Consistency level Bounded Staleness specified in the request is invalid when service is configured with consistency level Session". This error it self is wrong as Bounded Staleness was not mentioned in the code. If ConsistencyLevel = ConsistencyLevel.Eventual is used in the cosmosClientOptions there error does not appear.

To Reproduce

  1. Create a cosmos db instance with Session default consistency level
  2. Try to create a database in the cosmosdb instance via a code similar to the above - an exception will be thrown.

Expected behavior
There should not be any error if the cosmos client if instantiated with a weaker consistency than the default constituency defined in the cosmosdb instance.

Actual behavior
A misleading exception is being thrown.

Environment summary
SDK Version: Microsoft.Azure.Cosmos 3.16.0
Framework: .NET Core 3.1
OS Version: Windows 10 20H2 19042.746

Additional context
https://pbs.twimg.com/media/EtmPEIJU0AMtqvA?format=png&name=large

@j82w
Copy link
Contributor

j82w commented Feb 8, 2021

@IshamMohamed I was able to reproduce this. It seems to not show up when testing against the local emulator.

@j82w
Copy link
Contributor

j82w commented Feb 8, 2021

@IshamMohamed I found the bug. It's incorrectly converting the consistency levels. I'll send out a fix. This seems to have existed since 3.1.0. The fix will be released in the next few weeks.

return Documents.ConsistencyLevel.BoundedStaleness;

@IshamMohamed
Copy link
Author

Great!

@j82w
Copy link
Contributor

j82w commented Feb 15, 2021

@IshamMohamed please try the 3.17.0-preview release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has-repro Hotfix A hotfix is required for the issue
Projects
None yet
2 participants