fix: an account is not saved with only part of its sharing - #929
Merged
blaipr merged 1 commit intoSep 17, 2026
Merged
Conversation
AccountItems::addItems() wrapped all five sharing writes — view/edit groups, view/edit users, tags — in a catch (SPException) that logged and returned. So a failure part-way left the account saved with whatever subset had been inserted first, or with nothing shared at all if the first call threw, and the create answered with plain success. AccountToUserGroup, AccountToUser and AccountToTag each carry a foreign key to the row they name, so a group, user or tag deleted between the form being drawn and submitted throws a ConstraintException from inside one of them — an ordinary thing for two administrators to do to each other, not a contrived race. The edit path already does it right: replaceUserGroups() and replaceUsers() run inside transactionAware() and let failures propagate. Account::create() already wraps the whole create in transactionAware() too; what was missing was letting the failure reach it. testAddItemsWithException called addItems() with a throwing repository and no expectException, so it passed only because nothing propagated — it was pinning the swallow as intended behaviour. It now asserts the failure is reported.
blaipr
deleted the
fix/an-account-is-not-saved-with-only-part-of-its-sharing
branch
September 17, 2026 22:31
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.
AccountItems::addItems()wrapped all five sharing writes — view/edit groups, view/edit users, tags— in a
catch (SPException)that calledprocessException()and returned. So a failure part-wayleft the account saved with whatever subset had been inserted first, or with nothing shared at all
if the first call was the one that threw, and the create answered with plain success.
AccountToUserGroup,AccountToUserandAccountToTageach carry a foreign key to the row theyname, so a group, user or tag deleted between the form being drawn and the form being submitted
throws a
ConstraintExceptionfrom inside one of them. That is an ordinary thing for twoadministrators to do to each other on a busy installation, not a contrived race.
The edit path already does it right
updateItems()'sreplaceUserGroups()andreplaceUsers()run their delete-and-insert insidetransactionAware()and let failures propagate.Account::create()likewise already wraps thewhole create in
transactionAware()— what was missing was letting the failure reach it. Removingthe catch is the entire fix: the exception now rolls the account back with its sharing.
The test said so
testAddItemsWithExceptioncalledaddItems()with a throwing repository and noexpectException, so it passed only because nothing propagated — it was pinning the swallow asintended behaviour. It now asserts the failure is reported, and is renamed to say what it checks.
That is the second time in this repo a test has turned out to be describing a defect rather than a
decision (
deleteMultiplePartialMatchIsNotDetectedwas the first), which is worth knowing as asearch strategy.
Tests
testAddItemsReportsAFailureRatherThanSavingPartOfTheSharing— mutation-verified: it failsagainst the old
catch.testCreateIsAbandonedWhenItsSharingCannotBeApplied— asserts the account create abandons therest of its work and lets the failure out. This one is not a distinguisher: it mocks
AccountItemsService, so it passes before and after. It is here to pin thatAccount::create()does not itself catch, which is the other half of the guarantee.