Repository navigation
fix: release locks and delete preferences owned by deleted users - #18202
Open
santichausis wants to merge 1 commit into
Open
santichausis wants to merge 1 commit into
santichausis wants to merge 1 commit into
Conversation
Author
|
Could a maintainer approve the workflow run here? The I could only run the suites on SQLite locally (no Docker), so the MongoDB and Postgres runs are the part I can't verify myself — Happy to rebase or split anything out if that helps. Thanks! |
Deleting an auth collection document ran deleteUserPreferences after the document itself was deleted. On SQL adapters the preferences' user relationship rows cascade away with the user, so the query matched nothing and the preferences were left behind. Locks held by the user were never released at all, leaving behind a lock owned by no one that blocks other users until it expires. Both are now removed before the document is deleted, in deleteByID and in both bulk delete paths.
santichausis
force-pushed
the
fix/delete-user-locks-and-preferences
branch
from
October 12, 2026 21:59
e97b058 to
5fd6378
Compare
This branch has not been deployed
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.
What?
Deleting a user now releases the document locks that user holds and deletes their preferences, in
deleteByIDand in both bulkdeletepaths.Why?
Two things were left behind when an auth collection document was deleted (#18200):
deleteUserPreferencesran afterdb.deleteOne/db.deleteMany. Its query matches onuser.value, but by then thepayload_preferences_relsrow had already cascaded away with the user, so it matched nothing and preference rows piled up.payload_locked_documents_relsrow cascades away too, leaving a lock with nouser. Every lock check compareslock.user?.valuewith the current user, so that ownerless lock counts as "locked by someone else": the document can't be updated withoverrideLock: falseand shows as locked in the admin until the lock expires (5 minutes by default). On 3.x the edit view crashes instead (extractID(undefined)ingetIsLocked).How?
deleteUserDocumentLockshelper next to the existing bulk lock helpers incheckDocumentLockStatus.ts. It deletes locks whoseusermatches the deleted documents, and only runs for auth collections.deleteByID:deleteUserPreferencesanddeleteUserDocumentLocksnow run beforedb.deleteOne, inside the same transaction.delete: both run before the document delete in the per-document path (bulkOperationsSingleTransaction) and in the batched path. The trailingdeleteUserPreferencescall is removed. As a side effect, preferences are now only removed for documents that were actually deleted. Before, they were also removed for documents skipped because they were locked or failed inbeforeDelete.Trade-off: because the cleanup now runs before the delete, a failed
deleteManyon an adapter without transactions (e.g. MongoDB without a replica set) leaves the users in place with their preferences already removed. Running it afterwards isn't possible on SQL, and adapters with transactions roll it back.I left reader-side handling of ownerless locks (
getIsLocked,_userEditinginfind/findByID/findOne,handleFormStateLocking) out of this PR. With this change those locks are no longer created, and any that already exist expire on their own.Tests
New
test/locked-documents/delete-user.int.spec.ts: deleting a user by ID releases their lock (and the locked document can be updated again), deleting by ID removes their preferences, and a bulk delete removes the deleted user's lock and preferences while keeping another user's.locked-documents+authint suites pass on SQLite (114 tests), including withbulkOperationsSingleTransactionforced on to cover the per-document path.Fixes #18200