Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating an item in a Cosmos DB satellite region results in an error #2292

Open
3 tasks done
rwincewicz-alianza opened this issue Mar 6, 2025 · 3 comments
Open
3 tasks done
Assignees
Labels
Cosmos The azure_cosmos crate customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team

Comments

@rwincewicz-alianza
Copy link

Bug Title

No response

Crate Name

azure_data_cosmos

Crate Version

0.22.1

Description

I have a Cosmos DB account set up with 3 regions (UK South - primary, UK West and West US 2) and multi-region writes are enabled.

If COSMOSDB_URL is either the global URL (e.g. https://testdb.documents.azure.com:443/) or the region-specific URL for the primary region (e.g. https://testdb-uksouth.documents.azure.com:443/) then I can create items in the database as expected. If I use the region-specific URL for either of the satellite regions (e.g. https://testdb-ukwest.documents.azure.com:443/ or https://testdb-westus2.documents.azure.com:443/) then I get the error The requested operation cannot be performed at this region.

If I conduct the same test with the Cosmos DB Python SDK then I can create an item in each of the regions without errors by providing the region-specific URL to CosmosClient. I've confirmed using the Azure Portal metrics that the requests are in fact going to the specified regions.

Steps to Reproduce

  1. Create a Cosmos DB account with 3 regions (UK South - primary, UK West and West US 2), eventual consistency and multi-region writes are enabled.

  2. Run the following code with COSMOSDB_URL as the URL of the primary region. I'm using the key_auth feature in the azure_data_cosmos crate for simplicity.

use azure_core::credentials::Secret;
use serde::{Serialize, Deserialize};
use azure_data_cosmos::{clients::ContainerClient, CosmosClient};

#[derive(Serialize, Deserialize, Debug)]
struct Item {
    pub id: String,
    pub partition_key: String,
    pub value: String,
}

async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let item = Item {
        id: "1".into(),
        partition_key: "partition1".into(),
        value: "1".into(),
    };

    let cosmos_client: CosmosClient = CosmosClient::with_key("<COSMOSDB_URL>", Secret::from(<REDACTED>), None)?;
    
    let container: ContainerClient = cosmos_client.database_client("test").container_client("test");

    // Create an item
    container.create_item("1", item, None).await?;

    Ok(())
}

#[tokio::main]
async fn main() {
    let result = example().await;
    let _r = result.inspect(|x| println!("{:#?}", x)).inspect_err(|x| println!("{:#?}", x));
}
  1. Confirm that the item has been created in the data explorer
  2. Run the same code again but set COSMOSDB_URL to the URL of one of the satellite regions.
  3. Observe the error The requested operation cannot be performed at this region

Checklist

@github-project-automation github-project-automation bot moved this to Untriaged in Azure SDK Rust Mar 6, 2025
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 6, 2025
@RickWinter RickWinter added the Cosmos The azure_cosmos crate label Mar 6, 2025
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Mar 6, 2025
@github-project-automation github-project-automation bot moved this to Untriaged in Azure SDK Rust Mar 6, 2025
@analogrelay
Copy link
Member

At the moment, the Rust SDK doesn't support the x-ms-cosmos-allow-tentative-writes header required in order to write to the non-hub region. That's certainly something on our roadmap, but it's not present in this very early preview. You could use a custom policy to force the header in, but note that's not a tested and supported scenario at this time.

Thanks for the feedback though, we'll use this to help prioritize work as we continue to build out the official Rust SDK!

@analogrelay analogrelay added feature-request This issue requires a new behavior in the product in order be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 6, 2025
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Mar 6, 2025
@RickWinter RickWinter removed the feature-request This issue requires a new behavior in the product in order be resolved. label Mar 6, 2025
@rwincewicz-alianza
Copy link
Author

Ah, good to know. Thanks for the explanation.

@rwincewicz-alianza
Copy link
Author

I've just tested your suggestion of using a custom policy to set the x-ms-cosmos-allow-tentative-writes header and that worked nicely, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cosmos The azure_cosmos crate customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team
Projects
None yet
Development

No branches or pull requests

3 participants