Skip to content

fix(backends): keep forget() idempotent on azureblockblob and cosmosdb - #10714

Merged
auvipy merged 5 commits into
celery:mainfrom
inchang-ing:fix-forget-idempotent-azure-cosmos
Sep 27, 2026
Merged

auvipy merged 5 commits into
celery:mainfrom
inchang-ing:fix-forget-idempotent-azure-cosmos

Conversation

@inchang-ing

Copy link
Copy Markdown
Contributor

Fixes #10713

result.forget() on a missing result should be a no-op on every KV result
backend. Following the pattern established by #10697 (elasticsearch and
couchdb), this makes the two remaining backends idempotent as well:

  • celery/backends/azureblockblob.py: delete_blob() raising
    azure.core.exceptions.ResourceNotFoundError for a missing blob is now
    caught and treated as a no-op.
  • celery/backends/cosmosdbsql.py: DeleteDocument() raising HTTPFailure
    with status 404 (ERROR_NOT_FOUND) for a missing document is now caught
    and treated as a no-op, mirroring the existing handling in get().

Together with #10697, #10701 and #10702 this completes forget()
idempotency across all KV result backends.

Tests: two new unit tests per backend
(test_forget_missing_task_is_noop, test_forget_twice_is_noop) mirroring
the couchdb tests from #10697; t/unit/backends/test_azureblockblob.py and
t/unit/backends/test_cosmosdbsql.py pass (28 passed, 1 skipped).

@auvipy

auvipy commented Sep 27, 2026

Copy link
Copy Markdown
Member

@simpleqt can you try and review this?

@auvipy
auvipy self-requested a review September 27, 2026 08:12
@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.69%. Comparing base (d467a37) to head (713aafa).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10714   +/-   ##
=======================================
  Coverage   89.69%   89.69%           
=======================================
  Files         153      153           
  Lines       20421    20429    +8     
  Branches     2435     2436    +1     
=======================================
+ Hits        18316    18324    +8     
  Misses       1803     1803           
  Partials      302      302           
Flag Coverage Δ
unittests 89.67% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@MehrazRumman MehrazRumman 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.

Thanks @inchang-ing, this closes the gap nicely. With this PR plus #10697 (Elasticsearch/CouchDB) and #10701 (ArangoDB), forget() on a missing result is a no-op on every key-value result backend.

The fix

Azure Block Blob. Catching ResourceNotFoundError around delete_blob() is correct. The exception is already imported in the module's optional-import block and is already used the same way in get(), so this matches the existing code.

CosmosDB. Catching HTTPFailure and re-raising anything that isn't ERROR_NOT_FOUND is the right shape. It's the same pattern as the 404 handling in get() and the 409 handling in _create_database_if_not_exists() / _create_collection_if_not_exists(), and it doesn't hide throttling (429), auth, or server errors.

One thing worth a line in the code comment: on Azure, ResourceNotFoundError is raised both for a missing blob and for a missing container. For forget() both mean "nothing to delete", so ignoring both is fine, but it's worth saying so explicitly so nobody thinks it only covers the blob case.

Tests

The tests look good, and unlike #10697 the "twice" tests reuse the same key, so they test what their names say. A few small suggestions:

  1. Azure doesn't have a re-raise test. CosmosDB has test_delete_reraises_other_http_failures, but there's no Azure equivalent. Please add one that sets delete_blob.side_effect to a different azure.core.exceptions error (for example HttpResponseError or ResourceExistsError) and asserts that it propagates. That makes sure the except stays narrow.
  2. The test names say forget but the tests call delete(). Either rename them to test_delete_missing_key_is_noop / test_delete_twice_is_noop, or call self.backend.forget(task_id), which goes through _forget() and get_key_for_task() and so exercises the path users actually hit.
  3. Assert the key. The new tests don't check which blob or document was deleted. Adding get_blob_client.assert_called_with(container=..., blob=f'{base_path}mykey') (Azure) and DeleteDocument.assert_called_with('dbs/celerydb/colls/celerycol/docs/mykey', {'partitionKey': 'mykey'}) (CosmosDB) would make sure the exception is being ignored on the right call.

Nit

In cosmosdbsql.py, the not-found branch ends with return, while the Azure change (and the ES/CouchDB/Couchbase changes) use pass. Both work, since nothing comes after the try, but using pass would match the rest of the backend changes in this series.

Summary

The change is correct and follows the existing error handling in both backends. I'd approve as is. Points 1–3 are small test improvements and would be nice to have.

@auvipy
auvipy merged commit 395d289 into celery:main Sep 27, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

forget() is not idempotent on azureblockblob and cosmosdb result backends

3 participants