Description
- Package Name: azure-cosmos
- Package Version: 4.9.0
- Operating System: MacOS 15.3.2
- Python Version: 3.13.2
Describe the bug
replace_container always fails on containers that have uniqueKeyPolicy defined on them, even though there is no intention of modifying the uniqueKeyPolicy.
To Reproduce
Steps to reproduce the behavior:
- Create a container with a uniqueKeyPolicy using any method.
- Connect to the database, and obtain a
DatabaseProxy
object usingdb = get_database_client('db_name')
- Get the container client for the container created in step 1 using
container = db.get_container_client('container_name')
- Try to modify the indexing policy on the container using
db.replace_container(container=container, partition_key=container.read()['partitionKey'], indexing_policy=indexing_policy)
with any non-empty indexing policy object.
The operation fails with:
azure.cosmos.exceptions.CosmosHttpResponseError: (Forbidden) Message: {"Errors":["The unique index cannot be modified. To change the unique index, remove the collection and re-create a new one."]}
even though the unique index was not modified.
Expected behavior
The operation succeeds, the indexes contained in the indexingPolicy are modified to the indexing_policy
object passed in step 4, the unique indexes stay the same as before.
Screenshots
N/A
Additional context
I know the documentation mentions the unspecified parameters will be reset to the their default values, however the unique_key_policy parameter does not exist on the replace_container operation, which makes sense, as it cannot be modified. Keeping it as it is would be the desirable behaviour in this case, especially that the official guide does not present any alternative to update the indexes using an SDK. The operation can be performed rather easily using Azure Portal following the same guide:
https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-manage-indexing-policy?tabs=dotnetv3%2Cpythonv3
Metadata
Metadata
Assignees
Labels
Type
Projects
Status