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.57k stars 1.63k forks source link

Versions do not work on collections with custom IDs #5355

Open apetrisor opened 8 months ago

apetrisor commented 8 months ago

Link to reproduction

No response

Describe the Bug

This is a breaking bug.

Versions do not work on collections with custom IDs, on mongodb. (have not tested postgres)

You can create multiple versions, and list them, but when trying to access any version item you get a CastError:

Screenshot 2024-03-18 at 13 17 12

It happens whether you are using the admin UI or the REST API. This is because the system is trying to cast the _id of the version to the id type of the parent, and they obviously don't match. The issue lies in the db-mongodb package.

I found the solution, will submit a PR soon.

To Reproduce

  1. Create a collection with Number IDs and versions active.
  2. Create a document
  3. Create a new version for that document
  4. Try to access the version.

Payload Version

2.11.2

Adapters and Plugins

db-mongodb

mass8326 commented 1 day ago

I ran into this issue using PostgreSQL -- it is not a MongoDB only issue.