Repository navigation
fix(backends): keep forget() idempotent on azureblockblob and cosmosdb - #10714
Conversation
|
@simpleqt can you try and review this? |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
MehrazRumman
left a comment
There was a problem hiding this comment.
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:
- 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 setsdelete_blob.side_effectto a differentazure.core.exceptionserror (for exampleHttpResponseErrororResourceExistsError) and asserts that it propagates. That makes sure theexceptstays narrow. - The test names say
forgetbut the tests calldelete(). Either rename them totest_delete_missing_key_is_noop/test_delete_twice_is_noop, or callself.backend.forget(task_id), which goes through_forget()andget_key_for_task()and so exercises the path users actually hit. - 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) andDeleteDocument.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.
Fixes #10713
result.forget()on a missing result should be a no-op on every KV resultbackend. Following the pattern established by #10697 (elasticsearch and
couchdb), this makes the two remaining backends idempotent as well:
celery/backends/azureblockblob.py:delete_blob()raisingazure.core.exceptions.ResourceNotFoundErrorfor a missing blob is nowcaught and treated as a no-op.
celery/backends/cosmosdbsql.py:DeleteDocument()raisingHTTPFailurewith status 404 (
ERROR_NOT_FOUND) for a missing document is now caughtand 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) mirroringthe couchdb tests from #10697;
t/unit/backends/test_azureblockblob.pyandt/unit/backends/test_cosmosdbsql.pypass (28 passed, 1 skipped).