payload
payload copied to clipboard
fix(ui): upsert preferences to avoid missing id sequences
What?
- route
packages/ui/src/utilities/upsertPreferences.tsthroughreq.payload.db.upsertwhenever no preference row exists
Why?
-
req.payload.createdepended on Postgres auto-filling theid. On some real databases that default is missing, so the insert wroteNULLand the admin UI crashed. (deployments with driftedpayload_preferences.id(missing sequence/default) were throwingERROR: null value in column "id") - the REST preference update already uses
payload.db.upsert, which handles ID generation for serial/uuid/text setups and avoids the constraint violation
Example error
error: null value in column "id" of relation "payload_preferences" violates not-null constraint
at <unknown> (.next/server/chunks/7732.js:128:24554)
at async (.next/server/chunks/7732.js:68:23548)
at async oY.queryWithCache (.next/server/chunks/7732.js:68:20193)
at async (.next/server/chunks/7732.js:68:23337)
at async Object.aB [as insert] (.next/server/chunks/7732.js:48:23421)
at async r2 (.next/server/chunks/7732.js:26:41950)
at async Object.r4 [as create] (.next/server/chunks/7732.js:26:47748)
at async Z (.next/server/chunks/7732.js:144:39387)
at async l (.next/server/app/(payload)/admin/[[...segments]]/page.js:171:140710) {
length: 307,
severity: 'ERROR',
code: '23502',
detail: 'Failing row contains (null, collection-posts, {}, 2025-10-20 15:30:39.022+00, 2025-10-20 15:30:39.022+00).',
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: 'public',
table: 'payload_preferences',
column: 'id',
dataType: undefined,
constraint: undefined,
file: 'execMain.c',
line: '2009',
routine: 'ExecConstraints'
How?
- Use the same upsert call as
packages/payload/src/preferences/operations/update.ts, letting the adapter generate the primary key.