Fix upsert create item regression#4280
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR substantially refactors the Cosmos SDK to route more operations through the azure_data_cosmos_driver, updates item write APIs to require explicit item_id arguments (addressing upsert/create regressions), and adds new test gating, benchmarks, and a native-tls sample.
Changes:
- Migrates queries, database/container CRUD, and throughput offer operations to the driver pipeline; adds
ThroughputPollerfor async throughput replacement. - Updates item write call sites/tests/examples to pass explicit item IDs; introduces new response wrapper types (
ItemResponse,ResourceResponse,BatchResponse,QueryFeedPage) and diagnostics metadata. - Adds emulator/multi-write/split test gating via
cfg_attr(..., ignore), plus new benchmarks and a native-tls sample.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure_data_cosmos_driver/build.rs | Updates test_category cfg guidance for ignored-at-runtime tests. |
| sdk/cosmos/azure_data_cosmos_driver/Test-Setup.ps1 | Adds thin wrapper to shared Cosmos test setup script. |
| sdk/cosmos/azure_data_cosmos_driver/Test-Cleanup.ps1 | Adds thin wrapper to shared Cosmos test cleanup script. |
| sdk/cosmos/azure_data_cosmos_driver/Cargo.toml | Bumps driver version and reworks deps/features (reqwest/tls/tokio). |
| sdk/cosmos/azure_data_cosmos_driver/CHANGELOG.md | Records new driver features and releases. |
| sdk/cosmos/azure_data_cosmos_benchmarks/perfbench | Adds perf+speedscope helper script for bench profiling. |
| sdk/cosmos/azure_data_cosmos_benchmarks/benches/point_read.rs | Adds criterion benchmark for point reads (mock/live). |
| sdk/cosmos/azure_data_cosmos_benchmarks/README.md | Documents how to run benchmarks and profiling. |
| sdk/cosmos/azure_data_cosmos_benchmarks/Cargo.toml | Introduces new benchmarks crate wired to driver mocking. |
| sdk/cosmos/azure_data_cosmos/tests/split.rs | Adds split test harness module. |
| sdk/cosmos/azure_data_cosmos/tests/split_tests/mod.rs | Adds split tests module structure. |
| sdk/cosmos/azure_data_cosmos/tests/split_tests/cosmos_split_offers.rs | Adds long-running split throughput polling test with gating. |
| sdk/cosmos/azure_data_cosmos/tests/multi_write.rs | Switches multi_write tests from cfg-compilation to runtime ignore gating. |
| sdk/cosmos/azure_data_cosmos/tests/multi_write_tests/cosmos_multi_write_retry_policies.rs | Fixes create/upsert signatures to include item_id; adds test gating and request_url None handling. |
| sdk/cosmos/azure_data_cosmos/tests/multi_write_tests/cosmos_multi_write.rs | Updates routing log assertions and region types; adds test gating. |
| sdk/cosmos/azure_data_cosmos/tests/framework/mod.rs | Re-exports new helpers/constants for tests (connection string resolution, etc.). |
| sdk/cosmos/azure_data_cosmos/tests/framework/test_data.rs | Updates container_client and create_item usage to new signatures. |
| sdk/cosmos/azure_data_cosmos/tests/framework/mock_account.rs | Updates Region type usage and adds account-name-specific mock response helper. |
| sdk/cosmos/azure_data_cosmos/tests/emulator.rs | Switches emulator tests from cfg-compilation to runtime ignore gating. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/mod.rs | Adds new emulator test modules (backup endpoints, feed ranges, proxy). |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_query.rs | Adds pagination + metrics header coverage; gates emulator tests. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_proxy.rs | Adds proxy behavior integration tests. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_offers.rs | Updates throughput replace to async poller; adds gating. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_feed_ranges.rs | Adds integration tests for feed range APIs including HPK cases. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_databases.rs | Removes database throughput test; gates remaining emulator test. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_containers.rs | Updates partition key assertions and throughput replace polling; gates emulator tests. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_batch.rs | Updates create_item signature and operation options; gates emulator tests. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_backup_endpoints.rs | Adds integration test for backup endpoint bootstrap. |
| sdk/cosmos/azure_data_cosmos/src/transactional_batch.rs | Replaces if-match/if-none-match fields with Precondition; updates tests. |
| sdk/cosmos/azure_data_cosmos/src/routing_strategy.rs | Introduces RoutingStrategy public API for region selection. |
| sdk/cosmos/azure_data_cosmos/src/routing/partition_key_range_cache.rs | Fixes mixed addressing by using container name in pkranges link; adds tests. |
| sdk/cosmos/azure_data_cosmos/src/routing/mod.rs | Removes container_cache module from routing. |
| sdk/cosmos/azure_data_cosmos/src/routing/container_cache.rs | Deletes container cache implementation and tests. |
| sdk/cosmos/azure_data_cosmos/src/routing/async_cache.rs | Switches to azure_core::time::Duration and updates tests. |
| sdk/cosmos/azure_data_cosmos/src/retry_policies/metadata_request_retry_policy.rs | Updates Region/excluded regions handling and async tests. |
| sdk/cosmos/azure_data_cosmos/src/resource_context.rs | Makes RID helpers test-only; adds container_id accessor allowance. |
| sdk/cosmos/azure_data_cosmos/src/request_context.rs | Updates request context region type to Region. |
| sdk/cosmos/azure_data_cosmos/src/query/executor.rs | Replaces gateway executor with driver-based executor and page bridging. |
| sdk/cosmos/azure_data_cosmos/src/partition_key.rs | Adds conversion into driver partition key model. |
| sdk/cosmos/azure_data_cosmos/src/models/throughput_properties.rs | Adds helper to apply throughput headers to driver request headers. |
| sdk/cosmos/azure_data_cosmos/src/models/response_metadata.rs | Adds CosmosDiagnostics wrapper sourced from response headers. |
| sdk/cosmos/azure_data_cosmos/src/models/resource_response.rs | Adds ResourceResponse<T> wrapper for resource operations. |
| sdk/cosmos/azure_data_cosmos/src/models/mod.rs | Switches to wrapper response types + re-exports driver PK types. |
| sdk/cosmos/azure_data_cosmos/src/models/item_response.rs | Adds ItemResponse<T> with ETag/LSN accessors. |
| sdk/cosmos/azure_data_cosmos/src/models/batch_response.rs | Adds BatchResponse wrapper for transactional batch operations. |
| sdk/cosmos/azure_data_cosmos/src/models/account_properties.rs | Updates region type and adds per-partition failover behavior field. |
| sdk/cosmos/azure_data_cosmos/src/lib.rs | Re-exports new APIs (poller, routing strategy, feed range, response wrappers). |
| sdk/cosmos/azure_data_cosmos/src/hash.rs | Makes EPK sentinels pub(crate) and derives ordering for EPK type. |
| sdk/cosmos/azure_data_cosmos/src/handler/retry_handler.rs | Updates excluded regions field mapping. |
| sdk/cosmos/azure_data_cosmos/src/feed.rs | Introduces QueryFeedPage composition + richer feed page metadata accessors. |
| sdk/cosmos/azure_data_cosmos/src/fault_injection/rule.rs | Adds hit counting and passthrough status tracking to rules. |
| sdk/cosmos/azure_data_cosmos/src/fault_injection/result.rs | Adds CustomResponseBuilder and sub-status helper. |
| sdk/cosmos/azure_data_cosmos/src/fault_injection/mod.rs | Updates docs and re-exports new fault injection builder. |
| sdk/cosmos/azure_data_cosmos/src/fault_injection/http_client.rs | Simplifies rule state management by storing state in FaultInjectionRule. |
| sdk/cosmos/azure_data_cosmos/src/fault_injection/condition.rs | Updates region type to Region. |
| sdk/cosmos/azure_data_cosmos/src/fault_injection/client_builder.rs | Updates docs and adds internal accessor for rule list. |
| sdk/cosmos/azure_data_cosmos/src/cosmos_request.rs | Switches excluded regions to ExcludedRegions; removes container_id() helper. |
| sdk/cosmos/azure_data_cosmos/src/constants.rs | Adds offer LRO header name + circuit breaker env var constants. |
| sdk/cosmos/azure_data_cosmos/src/clients/throughput_poller.rs | Adds stream/await poller for throughput replacement completion. |
| sdk/cosmos/azure_data_cosmos/src/clients/offers_client.rs | Reworks offers querying/replacing to go through driver operations. |
| sdk/cosmos/azure_data_cosmos/src/clients/mod.rs | Introduces ClientContext and exports ThroughputPoller. |
| sdk/cosmos/azure_data_cosmos/src/clients/database_client.rs | Migrates DB operations to driver + introduces begin_replace_throughput. |
| sdk/cosmos/azure_data_cosmos/src/clients/cosmos_client.rs | Migrates account-level operations to driver; build now requires routing strategy. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/upsert.rs | Updates example to new item write option + explicit item_id. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/replace.rs | Updates examples for poller-based throughput replace and new options types. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/read.rs | Updates example for fallible container_client construction. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/query.rs | Updates example for fallible container_client construction. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/metadata.rs | Updates example for fallible container_client construction. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/main.rs | Adds required region arg and wires RoutingStrategy into client creation. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/delete.rs | Updates example for fallible container_client construction. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/create.rs | Updates item creation signature + removes DB throughput options in example. |
| sdk/cosmos/azure_data_cosmos/examples/cosmos/batch.rs | Updates example for fallible container_client construction. |
| sdk/cosmos/azure_data_cosmos/docs/RESPONSE_METADATA_SPEC.md | Adds design spec for typed response metadata wrappers. |
| sdk/cosmos/azure_data_cosmos/dev/dev.md | Clarifies that test_category gating ignores tests unless cfg is set. |
| sdk/cosmos/azure_data_cosmos/build.rs | Adds split to check-cfg allowed values and updates comment. |
| sdk/cosmos/azure_data_cosmos/Test-Setup.ps1 | Replaces inline setup script with thin wrapper to shared eng script. |
| sdk/cosmos/azure_data_cosmos/Test-Cleanup.ps1 | Replaces inline cleanup script with thin wrapper to shared eng script. |
| sdk/cosmos/azure_data_cosmos/README.md | Updates README for mandatory RoutingStrategy and fallible container_client. |
| sdk/cosmos/azure_data_cosmos/Cargo.toml | Bumps version and aligns deps/features with driver + TLS feature flags. |
| sdk/cosmos/azure_data_cosmos/CHANGELOG.md | Documents new features, breaking changes, and driver routing migration. |
| sdk/cosmos/AGENTS.md | Adds guidance on encoding semantics in traits + stronger assertions and runtime ignore notes. |
| sdk/cosmos/.github/skills/cosmos-pre-commit-validation/SKILL.md | Updates local validation guidance for test_category-gated tests. |
| sdk/cosmos/.github/skills/cosmos-design-struct/SKILL.md | Adds rule against parse/format round-trip tests. |
| sdk/cosmos/.cspell.json | Adds ignored words/paths for Cosmos area and extends dictionary. |
| sdk/core/typespec/src/http/headers.rs | Adds Headers::with_capacity constructor. |
| samples/cosmos_read_item_native_tls/src/main.rs | Adds native-tls Cosmos read-item sample using RoutingStrategy. |
| samples/cosmos_read_item_native_tls/infra/main.parameters.json | Adds azd parameters file for provisioning. |
| samples/cosmos_read_item_native_tls/infra/main.bicep | Adds infra to provision Cosmos account/db/container and RBAC assignment. |
| samples/cosmos_read_item_native_tls/azure.yaml | Adds azd project and postprovision hook (container + sample item intent). |
| samples/cosmos_read_item_native_tls/README.md | Documents native-tls sample usage and azd provisioning. |
| samples/cosmos_read_item_native_tls/Cargo.toml | Adds sample crate manifest with default-features disabled + native_tls. |
| eng/scripts/verify-dependencies.rs | Temporarily exempts cosmos crates from strict azure_core/identity pinning checks. |
| eng/scripts/Test-Semver.ps1 | Treats “not found in registry” as warning for unpublished packages. |
| eng/dict/crates.txt | Adds hdrhistogram and sysinfo crate names to dictionary. |
| Cargo.toml | Adds new Cosmos crates to workspace and benchmark profile section. |
| .vscode/cspell.json | Adds “splitmix” to VS Code spell ignore list. |
analogrelay
approved these changes
Apr 27, 2026
simorenoh
approved these changes
Apr 27, 2026
…FixUpsertCreateItemRegression
Member
Author
|
/azp run rust - cosmos - weekly |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
|
@microsoft-github-policy-service rerun |
dcbf722
into
Azure:release/azure_data_cosmos-previews
31 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This PR makes
create_itemandupsert_itemrequire an explicit item id, matching the pattern already used byread_item,replace_item, anddelete_item.Breaking Changes
azure_data_cosmos(SDK):ContainerClient::create_item()signature changed from(partition_key, item, options)to(partition_key, item_id, item, options)ContainerClient::upsert_item()signature changed from(partition_key, item, options)to(partition_key, item_id, item, options)azure_data_cosmos_driver(internal):CosmosOperation::create_item()now takesItemReferenceinstead of(ContainerReference, PartitionKey)CosmosOperation::upsert_item()now takesItemReferenceinstead of(ContainerReference, PartitionKey)All five point operations (
create_item,upsert_item,read_item,replace_item,delete_item) now follow the same pattern in both the SDK and the driver.Why
PR #4128 cut over more point operations to the driver but inadvertently removed the
ItemReference-based overloads forcreate_itemandupsert_item. This was a regression — the original design requires the caller to provide the item id explicitly so the driver never needs to parse the request body to extract the document id. Parsing the body in the driver is both unnecessary overhead and a layering violation (the SDK should own serialization concerns).How
cosmos_operation.rs):create_itemandupsert_itemfactory methods now takeItemReferenceand callSelf::new(OperationType::Create/Upsert, item), identical toread_item/delete_item/replace_item.operation_pipeline.rs):build_transport_requestdetects Create/Upsert Document operations and usescompute_feed_paths()instead ofcompute_paths(), since these operations POST to the collection feed URL even though the operation carries the item id.cosmos_resource_reference.rs): Addedcompute_feed_paths()to compute feed-style paths (parent URL + signing link) for references that carry a leaf id.container_client.rs):create_itemandupsert_itemnow acceptitem_id: &strand construct anItemReferencebefore delegating to the driver.Testing
Existing test coverage is sufficient