Azure / Azure/azure-sdk-for-python

[Bug] replace_container fails on containers with uniqueKeyPolicy

Aperta
#40,070 5 commenti 0 reazioni 1 assegnatario Rivendicata da @allenkim0129 Vedi su GitHub
bug Client Cosmos customer-reported needs-team-attention Service Attention
Lingua principale
Python
Stelle
5.6k
Fork
3.4k
Merge medio
2g
PR unite (30g)
217

Descrizione

- **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:
1. Create a container with a uniqueKeyPolicy using any method.
2. Connect to the database, and obtain a `DatabaseProxy` object using `db = get_database_client('db_name')`
3. Get the container client for the container created in step 1 using `container = db.get_container_client('container_name')`
4. 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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.