fix: a partly stale batch delete is not a success - #899
Merged
Conversation
deleteByIdBatch() in AuthToken, Client, Category and CustomFieldDefinition refused only when the delete affected zero rows; the other nine services compare the count against count($ids). So a selection of five items of which one had already been deleted removed four and reported all five as removed — the 'update that matched nothing, reported as saved' shape, asked as the wrong question rather than not asked at all. It was already known. Three of the four unit tests stubbed one affected row for five ids and passed, because 1 !== 0, and the integration test for the fourth was called deleteMultiplePartialMatchIsNotDetected, with a docblock pinning 'the current (weaker-than-Tag) behaviour in place'. Tag, which it names as the stronger sibling, has always compared against count($ids). That test now asserts the refusal and is renamed, and the other three services get the deleteMultiplePartialFailure test Tag already had. CustomFieldDefinition's check stays inside its transactionAware() closure, so the refusal takes the partial delete with it; the other three behave exactly as Tag and User already do.
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.
deleteByIdBatch()inAuthToken,Client,CategoryandCustomFieldDefinitionrefused onlywhen the delete affected zero rows. The other nine services compare the count against
count($ids). So a selection of five items of which one had already been deleted — by a colleague,or in an earlier attempt — removed four and reported all five as removed.
This is the shape the record already names as an update that matched nothing, reported as saved,
asked as the wrong question rather than not asked at all: the count was being read, and compared
against something that only catches the total failure.
It was known
Three of the four unit tests for these services stubbed one affected row for five ids and
passed, because
1 !== 0. And the integration test for the fourth was calleddeleteMultiplePartialMatchIsNotDetected, with a docblock saying it "pins the current(weaker-than-Tag) behaviour in place". That is a description of the defect, not a reason for it —
Tag, which it names as the stronger sibling, has always compared againstcount($ids), and hasboth a
deleteMultipleand adeleteMultiplePartialFailuretest.So the pinning test now asserts the refusal and is renamed
deleteMultiplePartialMatchIsRefused,and the other three services get the
deleteMultiplePartialFailuretestTagalready had.The change
Four
=== 0comparisons become!== count($ids). Nothing else moves:CustomFieldDefinition'scheck stays inside its
transactionAware()closure, so the refusal takes the partial delete withit; the other three have no transaction, and behave exactly as
Tag,Userand the rest already do— some rows removed, and an error saying the batch was not completed.
Tests
count($ids) - 1affected. Mutation-verified:reverting the four services fails all four, and only those four.
TagTest::deleteMultiplePartialFailure.deleteMultipletests now stub a full match explicitly, the wayTag'salready did, instead of relying on the harness default of one affected row.