{"record":{"id":"72558e1b01d14eef","repo":"payloadcms/payload","slug":"document-with-id-id-is-currently-locked-by-anot","errorCode":null,"errorMessage":"Document with ID ${id} is currently locked by another user and cannot be modified.","messagePattern":"Document with ID (.+?) is currently locked by another user and cannot be modified\\.","errorType":"exception","errorClass":"Locked","httpStatus":423,"severity":"warning","filePath":"packages/payload/src/utilities/checkDocumentLockStatus.ts","lineNumber":94,"sourceCode":"\n    // If there's a locked document, check lock conditions\n    const lockedDoc = lockedDocumentResult?.docs[0]\n    if (lockedDoc) {\n      const lastEditedAt = new Date(lockedDoc?.updatedAt).getTime()\n      const now = new Date().getTime()\n\n      const lockDuration =\n        typeof lockDocumentsProp === 'object' ? lockDocumentsProp.duration : lockDurationDefault\n\n      const lockDurationInMilliseconds = lockDuration * 1000\n      const currentUserId = req.user?.id\n\n      // document is locked by another user and the lock hasn't expired\n      if (\n        lockedDoc.user?.value !== currentUserId &&\n        now - lastEditedAt <= lockDurationInMilliseconds\n      ) {\n        throw new Locked(finalLockErrorMessage)\n      }\n    }\n  }\n\n  // Perform the delete operation regardless of overrideLock status\n  await payload.db.deleteMany({\n    collection: lockedDocumentsCollectionSlug,\n    // Not passing req fails on postgres\n    req: payload.db.name === 'mongoose' ? undefined : req,\n    where: lockedDocumentQuery,\n  })\n}\n","sourceCodeStart":76,"sourceCodeEnd":107,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/utilities/checkDocumentLockStatus.ts#L76-L107","documentation":"A `Locked` error thrown by `checkDocumentLockStatus` when a collection document is being modified by a request that does not hold the lock. Another user lock entry exists in the `locked-documents` collection, the lock holder is a different user, and the lock has not expired (within `lockDocuments.duration` seconds, default 300).","triggerScenarios":"A PATCH/DELETE on a collection document where `overrideLock` is `false` (default for the admin UI), `lockDocuments` is not `false`, and a recent `locked-documents` entry exists with a different `user.value` and an `updatedAt` within the lock duration window.","commonSituations":"Two admin users editing the same document concurrently; a user navigated away without saving, leaving a stale lock that has not expired yet; an automated script modifies a document a user currently has open in the admin panel; the lock duration is set very long and locks are not being released.","solutions":["Wait for the lock to expire (default 300s / 5 min) or have the locking user close the document.","Pass `overrideLock: true` in the Local API call if the operation should force through (use with caution).","Reduce `lockDocuments.duration` if locks linger too long.","Use `payload.db.deleteMany` on the `locked-documents` collection to manually clear a stuck lock if needed."],"exampleFix":"// before\nawait payload.update({\n  collection: 'posts',\n  id,\n  data: { title: 'New' },\n  // overrideLock defaults to true in Local API, but admin UI sets false\n})\n\n// after -- explicitly override when appropriate\nawait payload.update({\n  collection: 'posts',\n  id,\n  data: { title: 'New' },\n  overrideLock: true,\n})","handlingStrategy":"try-catch","validationCode":"// Before updating, check if the document is locked by another user\nconst locks = await payload.find({\n  collection: 'payload-locked-documents',\n  where: {\n    and: [\n      { 'document.relationTo': { equals: collectionSlug } },\n      { 'document.value': { equals: id } },\n    ],\n  },\n  depth: 1,\n})\nconst lock = locks.docs[0]\nif (lock && lock.user?.value !== currentUserId && Date.now() - new Date(lock.updatedAt).getTime() < 300000) {\n  throw new Error('Document is locked')\n}","typeGuard":null,"tryCatchPattern":"try {\n  await payload.update({ collection, id, data, overrideLock: false })\n} catch (e) {\n  if (e.name === 'Locked') {\n    // wait, notify user, or pass overrideLock: true if appropriate\n  } else throw e\n}","preventionTips":["In collaborative UIs, show lock status and warn before editing a locked document.","Use overrideLock: true only for intentional force-overrides.","Set a reasonable lockDocuments.duration (default 300s).","Release locks explicitly when a user navigates away if possible."],"tags":["locking","concurrency","document","admin"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}