Skip to content

[Bug] replace_container fails on containers with uniqueKeyPolicy #40070

Open
@conTroll

Description

@conTroll
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue points to a problem in the data-plane of the library.CosmosService AttentionWorkflow: This issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions