-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Owner Resource Not Found (Gateway V2 Connection Mode and Direct Connection Mode): Remaps sub-status to 1003 for requests to child resources against non-existent container. #47604
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
base: main
Are you sure you want to change the base?
Owner Resource Not Found (Gateway V2 Connection Mode and Direct Connection Mode): Remaps sub-status to 1003 for requests to child resources against non-existent container. #47604
Conversation
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds sub-status code 1003 (Owner Resource Not Found) for requests to child resources (e.g., documents) when the owning container doesn't exist. The changes ensure proper error reporting across Direct Mode, Gateway V2 Mode, and Gateway Mode connection types.
Key Changes
- Added error mapping logic to set sub-status code 1003 when container resolution fails during child resource operations
- Introduced new
setSubStatusCodemethod in CosmosException API via ImplementationBridgeHelpers - Added comprehensive test coverage for container not found scenarios across different connection modes
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| QueryPlanRetriever.java | Added error mapping to set sub-status 1003 for 404 errors during query plan retrieval |
| RxCollectionCache.java | Added error mapping handlers in collection resolution paths to set sub-status 1003 for child resource operations |
| StaleResourceRetryPolicy.java | Added enclosingOperationTargetResourceType parameter and error mapping logic for retry scenarios |
| RxDocumentClientImpl.java | Updated retry policy instantiation with ResourceType.Document parameter for point operations |
| ImplementationBridgeHelpers.java | Added setSubStatusCode method to CosmosExceptionAccessor interface |
| CosmosException.java | Implemented setSubStatusCode accessor method |
| CosmosNotFoundTests.java | New comprehensive test class covering non-existent and deleted container scenarios |
| FaultInjectionTestBase.java | Enhanced helper methods to support bulk operations and feed range testing |
| StaleResourceExceptionRetryPolicyTest.java | Updated test constructor calls with new null parameter |
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosNotFoundTests.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java
Show resolved
Hide resolved
...mos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/caches/RxCollectionCache.java
Outdated
Show resolved
Hide resolved
...mos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/caches/RxCollectionCache.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosNotFoundTests.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosNotFoundTests.java
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosNotFoundTests.java
Show resolved
Hide resolved
...mos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/StaleResourceRetryPolicy.java
Show resolved
Hide resolved
...mos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/caches/RxCollectionCache.java
Outdated
Show resolved
Hide resolved
| }).onErrorMap(throwable -> { | ||
| if (throwable instanceof CosmosException) { | ||
|
|
||
| CosmosException cosmosException = Utils.as(throwable, CosmosException.class); | ||
|
|
||
| if (!ResourceType.DocumentCollection.equals(request.getResourceType()) && com.azure.cosmos.implementation.Exceptions.isNotFound(cosmosException)) { | ||
| cosmosExceptionAccessor.setSubStatusCode(cosmosException, HttpConstants.SubStatusCodes.OWNER_RESOURCE_NOT_EXISTS); | ||
| } | ||
|
|
||
| return cosmosException; | ||
| } | ||
|
|
||
| return throwable; | ||
| }); |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error mapping logic is duplicated across multiple locations in this file (lines 95-108, 111-124, and 137-150). Consider extracting this into a private helper method to reduce duplication and improve maintainability.
…into AzCosmos_RemapSubStatusForDocRequestsAgainstNonExistentContainer
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| }) | ||
| .onErrorMap(throwable -> { | ||
|
|
||
| if (throwable instanceof CosmosException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, not sure this is the place for status code remapping since this is a retry policy - feels this logic should belong to RxCollectionCache only
| return cosmosException; | ||
| } | ||
|
|
||
| if (this.enclosingOperationTargetResourceType != null && !ResourceType.DocumentCollection.equals(this.enclosingOperationTargetResourceType) && Exceptions.isNotFound(cosmosException)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to check sub-status code as well?
|
|
||
| CosmosException cosmosException = Utils.as(throwable, CosmosException.class); | ||
|
|
||
| if (this.request != null && !ResourceType.DocumentCollection.equals(this.request.getResourceType()) && Exceptions.isNotFound(cosmosException)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need sub-status code checking?
| Mono<DocumentCollection> collectionObs = this.getByNameAsync(metaDataDiagnosticsContext, resourceFullName, request.properties); | ||
| return collectionObs.doOnSuccess(collection -> { | ||
| return collectionObs.onErrorMap(throwable -> { | ||
| return throwable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert the change here? there is no remapping of the error cases
Description
The objective of this PR is to add
Owner Resource Not Found(1003) as sub-status code mapping when the owning resource is not found specifically theDocumentCollectionresource. The main motivation is disambiguation - is it the child resource not present (such as a document) or its encapsulating resource such as a container. This can help an application developer debug better.Scenarios tested and fixed
For Direct Mode and Gateway V2 Mode, ensure both container never existed and stale container cache scenarios are appropriately handled.
For Gateway Mode, ensure container never existed scenarios are appropriately handled.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines