Skip to content

Failure to use azure-cosmos on Cosmos DB MongoDB server 3.6 #12186

@soderluk

Description

@soderluk
  • Package Name: azure-cosmos
  • Package Version: 4.0.0
  • Operating System: Ubuntu 18.04
  • Python Version: 3.6.8

Describe the bug
We're using Azure Cosmos DB in MongoDB compatibility mode, server version 3.6.

Using the azure-cosmos Python library, we just keep getting 404's all the time, e.g. CosmosResourceNotFoundError is raised.

The azure-cosmos DOES however work (to some extent) with the MongoDB server version 3.2. The "some extent" is that we can create the containers into the Cosmos DB database, but cannot run create_item() or read_all_items() on it, because we get the following error: azure.cosmos.exceptions.CosmosHttpResponseError: (Forbidden) Sql api is not supported for this database account

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Azure Cosmos DB instance, with MongoDB, server version 3.6
  2. Manually create a new database in Cosmos DB
  3. Try to create a new container into the database with the azure-cosmos library:
client = CosmosClient("https://xxx.mongo.cosmos.azure.com", credential="xxx")
db = client.get_database_client("test_database")
db.create_container_if_not_exists(
    id="test_container",
    partition_key=PartitionKey(path="/'$v'/_id/'$v'", version=1),
    unique_key_policy={"uniqueKeys": [{"paths": ["/name"]}]},
)

Expected behavior
The container named "test_container" should be created, with the shard key /_id and unique key /name.

Stack trace

Request URL: 'https://xxx.mongo.cosmos.azure.com/dbs/test_database/colls/'
Request method: 'POST'
Request headers:
    'Cache-Control': 'no-cache'
    'x-ms-version': 'REDACTED'
    'x-ms-documentdb-query-iscontinuationexpected': 'REDACTED'
    'x-ms-consistency-level': 'REDACTED'
    'x-ms-date': 'REDACTED'
    'authorization': 'REDACTED'
    'Content-Type': 'application/json'
    'Accept': 'application/json'
    'Content-Length': '162'
    'User-Agent': 'azsdk-python-cosmos/4.0.0 Python/3.6.8 (Linux-4.19.107-x86_64-with)'
Response status: 404
Response headers:
    'Transfer-Encoding': 'chunked'
    'Server': 'Microsoft-HTTPAPI/2.0'
    'Date': 'Wed, 24 Jun 2020 06:58:20 GMT'
Traceback (most recent call last):
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/database.py", line 271, in create_container_if_not_exists
    **kwargs
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/core/tracing/decorator.py", line 83, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/container.py", line 146, in read
    collection_link, options=request_options, **kwargs
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/_cosmos_client_connection.py", line 468, in ReadContainer
    return self.Read(path, "colls", collection_id, None, options, **kwargs)
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/_cosmos_client_connection.py", line 2161, in Read
    result, self.last_response_headers = self.__Get(path, request_params, headers, **kwargs)
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/_cosmos_client_connection.py", line 2216, in __Get
    **kwargs
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/_synchronized_request.py", line 218, in SynchronizedRequest
    **kwargs
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/_retry_utility.py", line 73, in Execute
    result = ExecuteFunction(function, global_endpoint_manager, *args, **kwargs)
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/_retry_utility.py", line 130, in ExecuteFunction
    return function(*args, **kwargs)
  File "~/.venvs/test-py3.6/lib/python3.6/site-packages/azure/cosmos/_synchronized_request.py", line 152, in _Request
    raise exceptions.CosmosResourceNotFoundError(message=data, response=response)
azure.cosmos.exceptions.CosmosResourceNotFoundError: Status code: 404
b''

Metadata

Metadata

Labels

ClientThis issue points to a problem in the data-plane of the library.Cosmoscustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions