Race condition causing documents to disappear from CMS
Link to reproduction
https://github.com/rymate1234/payload-draft-reprod
Describe the Bug
This appears to be an issue relating to how Payload stores versions in the underlying database.
In order for the CMS to get the latest version (including any drafts) it queries the versions table for the entity looking for a document where the latest is true.
We believe we've encountered a race condition whereby if a document gets multiple versions persisted at the same time (for instance if an autosave is happening at the same time as a document is published) this can cause there to be a state where no document in the database has the latest version. Because of this, the document will no longer appear in cms lists, only on individual document views
To Reproduce
In the reproduction repo, I have created a worker-race task that will do two database writes at the same time to a document.
It may take a few attempts for the reproduction to occur but it does seem to happen most times with my reproduction repo.
Payload Version
Adapters and Plugins
No response