Skip to content

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
microsoft:mainfrom
jonnyry:feature/api-try-update-with-retries-fix
Closed

Prevent AttributeError failure when the API attempts a database update retry after initially failing with an etag mismatch#5023
Jonny Rylands (jonnyry) wants to merge 4 commits into
microsoft:mainfrom
jonnyry:feature/api-try-update-with-retries-fix

Conversation

@jonnyry

Copy link
Copy Markdown
Collaborator

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.

Copilot AI review requested due to automatic review settings August 1, 2026 21:22
@jonnyry
Jonny Rylands (jonnyry) requested a review from a team as a code owner August 1, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_app patch version to 0.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.

Comment thread CHANGELOG.md Outdated
Comment thread api_app/service_bus/helpers.py
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(
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

Unit Test Results

724 tests   724 ✅  8s ⏱️
  1 suites    0 💤
  1 files      0 ❌

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>
Copilot AI review requested due to automatic review settings August 1, 2026 21:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 successful Resource is returned to the caller (not None). Adding a test for the “fail once, succeed once” path would prevent this from regressing (e.g., extend api_app/tests_ma/test_service_bus/test_resource_request_sender.py to make patch_resource raise once then return (resource, template), and assert try_update_with_retries returns the resource and calls patch_resource twice).
    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,

@jonnyry

Copy link
Copy Markdown
Collaborator Author

Closing... work moved to PR #5025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants