payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
25.73k stars 1.64k forks source link

Documents showing locked by current user #8589

Closed tylandavis closed 1 month ago

tylandavis commented 1 month ago

Link to reproduction

No response

Environment Info

Binaries: Node: 22.6.0 npm: 10.8.2 Yarn: 1.22.22 pnpm: 9.7.1 Relevant Packages: payload: 3.0.0-beta.111 next: 15.0.0-canary.173 @payloadcms/db-mongodb: 3.0.0-beta.111 @payloadcms/email-nodemailer: 3.0.0-beta.111 @payloadcms/graphql: 3.0.0-beta.111 @payloadcms/live-preview: 3.0.0-beta.111 @payloadcms/live-preview-react: 3.0.0-beta.111 @payloadcms/next/utilities: 3.0.0-beta.111 @payloadcms/plugin-cloud: 3.0.0-beta.111 @payloadcms/plugin-cloud-storage: 3.0.0-beta.111 @payloadcms/plugin-form-builder: 3.0.0-beta.111 @payloadcms/plugin-nested-docs: 3.0.0-beta.111 @payloadcms/plugin-redirects: 3.0.0-beta.111 @payloadcms/plugin-seo: 3.0.0-beta.111 @payloadcms/richtext-lexical: 3.0.0-beta.111 @payloadcms/storage-vercel-blob: 3.0.0-beta.111 @payloadcms/translations: 3.0.0-beta.111 @payloadcms/ui/shared: 3.0.0-beta.111 react: 19.0.0-rc-3edc000d-20240926 react-dom: 19.0.0-rc-3edc000d-20240926 Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 Available memory (MB): 16384 Available CPU cores: 12

Describe the Bug

When opening documents, locked document warning message is showing, saying that the document is being edited by the current user. This is happening for all documents, regardless of actual locked status, and even for a brand new user who has never edited documents before.

Video of issue: https://github.com/user-attachments/assets/63fbdd4d-aeab-488c-812f-39eeda231512

Reproduction Steps

Adapters and Plugins

db-mongodb, storage-vercel-blob, richtext-lexical, plugin-seo, plugin-redirects, plugin-form-builder, email-nodemailer

drewlonious commented 1 month ago

I'm getting this as well, with postgres.

mikecebul commented 1 month ago

With SQLite (same environment) the lock documents from another user will stay locked indefinitely, until you 'take over'. Last test it stayed locked for 5 hours with no one logging in.

PatrikKozak commented 1 month ago

Hey @drewlonious and @mikecebul,

Thank you both for reporting this issue.

After reviewing the issue, it seems that the initial document locking problem may be related to a recent change made in the MongoDB adapter, where relationships are now stored as ObjectIDs instead of strings. This caused a bug in certain beta versions (v3.0.0-beta.108 to around v3.0.0-beta.110), leading to stale documents appearing twice in the list view. This bug has since been resolved in the release (v3.0.0-beta.111).

However @drewlonious, since you mentioned that this issue also appeared in your Postgres project, could you please provide additional reproduction steps or describe how you encountered the issue?

In the meantime, for those who encountered this with MongoDB, we recommend saving a new version of each document that appears as a duplicate. Additionally, clearing out any entries from the payload-locked-documents collection in your database should remove any stale locks caused by these duplicates.

We encountered the same issue in our website CMS and found that these steps resolved it. If you run into any issues with this process or need further clarification, please feel free to reach out, and I’d be happy to assist.

@Mikecebul – Regarding the behavior you're experiencing: Currently, this is by design. The document edit view relies on an unmount function to remove the lock when a user navigates away. However, if a page refresh occurs or the user steps away without leaving the document, the unmount function doesn’t get triggered, and the lock remains.

We’re actively exploring alternative solutions to address this scenario, but for now, the Take Over option is provided to ensure that other users aren't blocked by stale locks. Additionally, the overrideLock option in the Local API can help manage updates on documents that remain locked. I hope this explanation helps clarify the situation.

mikecebul commented 1 month ago

That makes sense, thanks for the explanation.

PatrikKozak commented 1 month ago

Fixed with #8744

github-actions[bot] commented 1 month ago

🚀 This is included in version v3.0.0-beta.116

BrianJM commented 1 month ago

After reviewing the issue, it seems that the initial document locking problem may be related to a recent change made in the MongoDB adapter, where relationships are now stored as ObjectIDs instead of strings. This caused a bug in certain beta versions (v3.0.0-beta.108 to around v3.0.0-beta.110), leading to stale documents appearing twice in the list view. This bug has since been resolved in the release (v3.0.0-beta.111).

However @drewlonious, since you mentioned that this issue also appeared in your Postgres project, could you please provide additional reproduction steps or describe how you encountered the issue?

In the meantime, for those who encountered this with MongoDB, we recommend saving a new version of each document that appears as a duplicate. Additionally, clearing out any entries from the payload-locked-documents collection in your database should remove any stale locks caused by these duplicates.

We encountered the same issue in our website CMS and found that these steps resolved it. If you run into any issues with this process or need further clarification, please feel free to reach out, and I’d be happy to assist.

@PatrikKozak I am using release v3.0.0-beta.116 with MongoDB (local). Document locks are added immediately after changing a value in the UI (i.e., on blur/change). The screenshot below appears and a document is added to payload-locked-documents.

Rolling back to 3.0.0-beta.107 resolves the issue, as well as setting lockDocuments: false in each CollectionConfig.

Image Image

github-actions[bot] commented 4 weeks ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.