website template: the seed button fails intermittently with a deadlock, because the seed clears collections in parallel
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- nextjs, postgresql, typescript
Direzione di ricerca
Il problema si trova in src/endpoints/seed/index.ts del template del sito web, dove il passaggio di pulizia esegue Promise.all sulla lista collections. Inizia riproducendo il problema con il repository collegato payload-website-seed-race: premi ripetutamente il pulsante seed su Postgres e controlla la presenza di errori 40P01 e 23502. È completato quando il seed svuota le collections in un ordine sicuro, con form-submissions prima di forms, e le esecuzioni ripetute non falliscono più.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the Bug
The website template's seed (src/endpoints/seed/index.ts, behind POST /next/seed) clears its collections with Promise.all(collections.map((collection) => payload.db.deleteMany({ collection, req, where: {} }))). There is no transaction, so each delete runs on its own pool connection, all at once. On Postgres this fails in two ways:
- Deadlock (
40P01), even with only the seed's own data.delete from "media"sets the references inpages_blocks_media_blockandpoststo null (ON DELETE SET NULL), whiledelete from "pages"/delete from "posts"deletes the same rows in a different order. The Postgres log showsdeadlock detectedwhile deleting tuples inpages_blocks_media_blockandposts. - Not-null violation (
23502) once the contact form has a submission. Whenformsis cleared beforeform-submissions, it hits #11177.
Measured on a new app, production build (pnpm build && pnpm start), Postgres 18:
| Scenario | Failed runs |
|---|---|
| Seed button pressed again, seed data only | 4 of 30 (40P01) |
| One contact form submission before each run | 4 of 8 (three 23502, one 40P01) |
Each delete commits on its own, so a failed run leaves the collections partly cleared. After one failed run, pages still had 2 rows, the contact page among them, while forms, posts and media were empty; the contact page's form block then points at nothing, and the next pnpm build fails prerendering /contact with TypeError: Cannot destructure property 'id' of '{}' as it is null.
Suggested fix (measured: 0 failures in the same 38 runs). Clear the collections one at a time, with form-submissions before forms. That is the PostgreSQL manual's own advice on deadlocks: take locks in a consistent order (https://www.postgresql.org/docs/18/explicit-locking.html#LOCKING-DEADLOCKS).
@@ -16,6 +16,6 @@ const collections: CollectionSlug[] = [
'pages',
'posts',
- 'forms',
'form-submissions',
+ 'forms',
'search',
]
@@ -60,7 +60,8 @@ export const seed = async ({
)
- await Promise.all(
- collections.map((collection) => payload.db.deleteMany({ collection, req, where: {} })),
- )
+ // One at a time: parallel deletes of related tables deadlock, and a form can only go after its submissions.
+ for (const collection of collections) {
+ await payload.db.deleteMany({ collection, req, where: {} })
+ }
The same code is on main today (https://github.com/payloadcms/payload/blob/1b1a9ca2040202def9004f379207bd17dd230443/templates/website/src/endpoints/seed/index.ts#L63-L65). I can open a PR with this change if that helps.
Link to the code that reproduces this issue
https://github.com/brunoccalmeida/payload-website-seed-race (untouched app from [email protected] -t website --db postgres plus the generated migration on main; the suggested fix is on the fix/seed-sequential branch)
Reproduction Steps
npx [email protected] -t website --db postgres, pointing at an empty Postgres 18 database.pnpm payload migrate:create && pnpm payload migrate, thenpnpm build && pnpm start.- Create the first admin user, then click "Seed your database" on the dashboard.
- Click it again a few times. Some clicks fail with
Error seeding data.and the log showsdeadlock detected. - Optionally, submit the form on
/contactbefore clicking: about half the clicks then fail, mostly with23502.
Which area(s) are affected?
area: templates, db: postgres
Environment Info
Binaries:
Node: 26.13.1
npm: N/A
Yarn: N/A
pnpm: 11.28.9
Relevant Packages:
payload: 3.94.2
next: 16.4.6
@payloadcms/db-postgres: 3.94.2
@payloadcms/drizzle: 3.94.2
@payloadcms/graphql: 3.94.2
@payloadcms/live-preview: 3.94.2
@payloadcms/live-preview-react: 3.94.2
@payloadcms/next/utilities: 3.94.2
@payloadcms/plugin-form-builder: 3.94.2
@payloadcms/plugin-nested-docs: 3.94.2
@payloadcms/plugin-redirects: 3.94.2
@payloadcms/plugin-search: 3.94.2
@payloadcms/plugin-seo: 3.94.2
@payloadcms/richtext-lexical: 3.94.2
@payloadcms/translations: 3.94.2
@payloadcms/ui/shared: 3.94.2
react: 19.2.9
react-dom: 19.2.9
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro
Available memory (MB): 32689
Available CPU cores: 20
PostgreSQL: 18 (Docker)
- Lingua principale
- TypeScript
- Stelle
- 46.1k
- Fork
- 4.5k
- Merge medio
- 2g 15h
- PR unite (30g)
- 238
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di payloadcms/payload
-
db-postgres: date-only range on a single field drops every operator after the first (greater_than_equal + less_than_equal)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
payloadcms/payload#20110 ·
I maintainer di solito rispondono entro 1 giorno
-
Uploading a file whose name ends in a long number loops forever when the name is takenForse già presa @JayPokale l’ha presa 7 giorni fa. Apertaarea: core Bug community-pr Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
payloadcms/payload#19978 ·
I maintainer di solito rispondono entro 1 giorno
-
[v4] A row whose fields are all hidden by their conditions still adds a field margin (regression from v3)Forse già presa @paulw1982 l’ha presa 7 giorni fa. Apertaarea: ui Bug community-pr created-by: Contributor Payload OSS status: needs-triage v3-only
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
payloadcms/payload#19976 ·
I maintainer di solito rispondono entro 1 giorno
-
[v3] Maximum update depth exceeded opening a document from the list view with cacheComponents: true (dev): backport #18702's CloseModalOnRouteChange guardForse di nuovo libera @MuhammadAhmad67889 l’ha presa 8 giorni fa e non c’è nessuna pull request aperta. Apertaarea: ui Bug Payload OSS
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
payloadcms/payload#19954 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
refresh operation throws a TypeError (500) when the session is revoked between the JWT strategy read and its own readForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertaarea: core Bug Payload OSS
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
payloadcms/payload#19867 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di payloadcms/payload
Issue simili
-
clawsweeper:intake:bug clawsweeper:intake:needs-environment
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
openclaw/openclaw#212827 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
KT-2245 e2e specs that call the backend directly fall back to the developer's own Kronn on :3140Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Use one constant for the 10,000-character input limitForse già presa @NginxL l’ha presa oggi. Apertagood first issue refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
aniru-dh21/snap-validate#51 ·
I maintainer di solito rispondono entro 1 giorno
-
dependencies effort: small good first issue priority: low
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
TMHSDigital/screencast-mcp#509 ·
I maintainer di solito rispondono entro 1 giorno
-
from-review tech-debt testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
blamechris/chroxy#9520 ·
I maintainer di solito rispondono entro 1 giorno