Skip to content

Handle successful resource update retries correctly - #5025

Open
Jonny Rylands (jonnyry) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-code-review-comment-5023
Open

Handle successful resource update retries correctly#5025
Jonny Rylands (jonnyry) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-code-review-comment-5023

Conversation

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

TLDR

This line below missing a return which causes a AttributeError up the call stack. This line is only rarely called when a database update is in retry due to a mismatch in ETag.

await try_update_with_retries(

Longer version (Copilot):

What is being addressed

try_update_with_retries(...) retried on CosmosAccessConditionFailedError, but a successful recursive retry did not propagate the patched Resource back to the caller. The existing tests covered the exhausted-retries case only, so this success path was unverified.

How is this addressed

  • Retry return path

    • Return the recursive try_update_with_retries(...) result so a successful retry yields the updated Resource to the original caller.
  • Regression coverage

    • Add a focused test for the retry sequence where:
      1. the first patch_resource(...) raises CosmosAccessConditionFailedError
      2. the next retry succeeds
      3. try_update_with_retries(...) returns the patched Resource
      4. patch_resource(...) and get_resource_by_id(...) are each called twice
  • Illustrative change

    if attempt_count < num_retries:
        return await try_update_with_retries(...)
  • Update documentation

    • No documentation changes were needed for this scoped fix.
  • Update CHANGELOG.md if needed

    • Not updated; this PR only addresses the reviewed retry-path behavior.
  • Increment template version if needed, for guidelines see Authoring templates - versioning

    • Not applicable.

Copilot AI requested review from Copilot and removed request for Copilot August 1, 2026 21:47
Copilot AI changed the title [WIP] Fix the code based on review comment for PR 5023 Handle successful resource update retries correctly Aug 1, 2026
@jonnyry
Jonny Rylands (jonnyry) marked this pull request as ready for review August 1, 2026 21:51
@jonnyry
Jonny Rylands (jonnyry) requested a review from a team as a code owner August 1, 2026 21:51
Copilot AI review requested due to automatic review settings August 1, 2026 21:51
@jonnyry

Copy link
Copy Markdown
Collaborator

Copilot please can you update the CHANGELOG and the api version number

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.

🟡 Not ready to approve

The code change appears correct, but the repo’s guidance indicates significant changes should be recorded in CHANGELOG.md and this PR introduces a behavioral bug fix without an entry.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Fixes try_update_with_retries(...) so that when an update succeeds after retrying an CosmosAccessConditionFailedError (etag mismatch), the successful patched Resource is returned to the original caller, and adds regression coverage for the success-after-retry path.

Changes:

  • Return the result of the recursive retry call in try_update_with_retries(...) so successful retries propagate the updated Resource.
  • Add a test that simulates an etag mismatch on the first patch attempt and success on the second, asserting the updated Resource is returned and the expected calls occur.
File summaries
File Description
api_app/service_bus/helpers.py Fixes retry recursion to return the successful patched Resource to the original caller.
api_app/tests_ma/test_service_bus/test_resource_request_sender.py Adds regression test to cover the successful retry path and validate call counts/return value.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread api_app/tests_ma/test_service_bus/test_resource_request_sender.py
Comment thread api_app/service_bus/helpers.py
Copilot AI requested review from Copilot and removed request for Copilot August 1, 2026 21:57

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Copilot please can you update the CHANGELOG and the api version number

Done in eb3d3b5 — I added the CHANGELOG bug-fix entry and bumped the API version to 0.26.1.

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.

3 participants