Prevent AttributeError failure when the API attempts a database update retry after initially failing with an etag mismatch - #5023
Closed
Jonny Rylands (jonnyry) wants to merge 4 commits into
Conversation
Prevent AttributeError during database update retry after etag failure.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the TRE API’s CosmosDB update retry path where an initial ETag mismatch followed by a successful retry could still cause the caller to fail due to a missing returned Resource. It also records the fix in the changelog and bumps the API patch version.
Changes:
- Propagate the successful retry result by returning the recursive
try_update_with_retries(...)call result. - Bump
api_apppatch version to0.26.1. - Add a BUG FIXES entry describing the retry/ETag issue.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| CHANGELOG.md | Adds a bug-fix entry for the ETag mismatch retry issue. |
| api_app/service_bus/helpers.py | Fixes the retry path to return the updated Resource from a successful retry attempt. |
| api_app/_version.py | Increments the API patch version to reflect the bug fix. |
| logger.warning(f"Etag mismatch for {resource_to_update_id}. Retrying.") | ||
| if attempt_count < num_retries: | ||
| await try_update_with_retries( | ||
| return await try_update_with_retries( |
Unit Test Results724 tests 724 ✅ 8s ⏱️ Results for commit 1a0fe9d. ♻️ This comment has been updated with latest results. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
api_app/service_bus/helpers.py:134
- The retry path is now correctly returning the result, but there’s no regression test covering the specific scenario this PR fixes: first Cosmos patch raises
CosmosAccessConditionFailedError, then a subsequent retry succeeds and the successfulResourceis returned to the caller (notNone). Adding a test for the “fail once, succeed once” path would prevent this from regressing (e.g., extendapi_app/tests_ma/test_service_bus/test_resource_request_sender.pyto makepatch_resourceraise once then return(resource, template), and asserttry_update_with_retriesreturns the resource and callspatch_resourcetwice).
except CosmosAccessConditionFailedError as e:
logger.warning(f"Etag mismatch for {resource_to_update_id}. Retrying.")
if attempt_count < num_retries:
return await try_update_with_retries(
num_retries=num_retries,
Collaborator
Author
|
Closing... work moved to PR #5025 |
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.
If a Cosmos update fails due to an etag mismatch, and the retry succeeds - the calling code then fails due to no return value passed back.
The occured while two services were installing and both updating the firewall in the pipeline. Unfortunately I don't have the error log anymore as the test system is torn down.