Description
openedon Sep 2, 2020
- Package Name: azure-cosmos
- Package Version: 4.1.0
- Operating System: Ubuntu 18.04 LTS
- Python Version: 3.8
Describe the bug
I created a test CosmosDB database using the Azure web portal with the examples from the CosmosDB Getting Started documentation.
{
"id": "AndersenFamily",
"children": ["..."],
"..."
},
{
"id": "WakefieldFamily",
"children": ["..."],
"..."
},
I set the partition_key
on the container to be the "id"
field. I can run the following queries (from the SQL Query Object Array page) via the "Data Explorer" on the Azure web portal just fine, but the Python SDK has issues when I set partition_key
on the query.
The following two queries work fine in Data Explorer on the Azure web portal:
SELECT * FROM Families.children
SELECT * FROM c IN Families.children
Both queries throw errors in the Python SDK when I pass a partition_key
parameter to query_items()
:
import os
from azure.cosmos.cosmos_client import CosmosClient
client = CosmosClient(os.environ['COSMOS_ENDPOINT'], credential=os.environ['COSMOS_KEY'])
container = client.get_database_client('testdb').get_container_client('testcontainer')
query1 = 'SELECT * FROM Families.children'
query2 = 'SELECT * FROM c IN Families.children'
# these work just fine
list(container.query_items(query=query1, enable_cross_partition_query=True))
list(container.query_items(query=query2, enable_cross_partition_query=True))
# both of these throw the same error
list(container.query_items(query=query1, partition_key='AndersenFamily'))
list(container.query_items(query=query2, partition_key='AndersenFamily'))
CosmosHttpResponseError: (BadRequest) Message: {"errors":[
{"severity":"Error","location":{"start":4294967295,"end":4294967295},"code":"SC2001","message":"Identifier 'Families' could not be resolved."}]}
ActivityId: 5e53c5f6-43bc-43ee-90a7-4e39d48aa271, [...]
Expected behavior
Setting partition_key
on query_items()
should not cause an error.
Additional context
I suspect that this may be related to the bug reported in #11721. However, my example here is much simpler and identifies the issue with passing a partition_key
argument to query_items()
.