docs: add warning about unique fields with drafts enabled#16096
Open
efe-arv wants to merge 1 commit intopayloadcms:mainfrom
Open
docs: add warning about unique fields with drafts enabled#16096efe-arv wants to merge 1 commit intopayloadcms:mainfrom
efe-arv wants to merge 1 commit intopayloadcms:mainfrom
Conversation
Document the known limitation where `unique: true` fields on collections with `versions.drafts` enabled cause silent document creation failures. The Admin UI redirects to `?notFound=<id>` with no error message. This has been an open issue since 2022 (payloadcms#953, payloadcms#12628, payloadcms#3576) affecting users on both MongoDB and PostgreSQL/Drizzle adapters. Added: - Warning banner in Database changes section - New 'Unique fields with Drafts' section with: - Problem explanation - Application-level uniqueness workaround using validate + index - Code example Relates to payloadcms#953, payloadcms#12628, payloadcms#3576
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
Adds documentation about a known limitation where
unique: truefields on collections withversions.draftsenabled cause silent document creation failures.The Problem
When a drafts-enabled collection has fields with
unique: true, creating new documents can fail silently:_collection_v)UNIQUEconstraint conflicts during the draft creation process?notFound=<id>with no visible error messageThis affects all database adapters (PostgreSQL/Drizzle and MongoDB) and has been reported multiple times:
What This PR Adds
unique: truewithindex: true+ application-levelvalidatefunctionThe Workaround
Context
We hit this in production on a legal CMS (Payload 3.64.0 + PostgreSQL on Fly.io) with 5,000+ tags. The collection had
versions.draftsenabled withunique: trueon bothnameandslugfields. Tag creation was completely broken with no error feedback — just a?notFound=redirect. Replacing the DB-level unique constraint with an application-level validate function resolved it immediately.Ideally Payload would handle this gracefully at the framework level (e.g., deferring unique validation for draft documents, or surfacing a clear error), but until then, this documentation helps others avoid the same trap.