Skip to content

[CosmosDB] Query fails when setting partition_key #13519

Closed

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.CosmosService AttentionWorkflow: This issue is responsible by Azure service team.customer-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