payload icon indicating copy to clipboard operation
payload copied to clipboard

fix(ui): upsert preferences to avoid missing id sequences

Open hassanthegooner opened this issue 5 months ago • 0 comments

What?

  • route packages/ui/src/utilities/upsertPreferences.ts through req.payload.db.upsert whenever no preference row exists

Why?

  • req.payload.create depended on Postgres auto-filling the id. On some real databases that default is missing, so the insert wrote NULL and the admin UI crashed. (deployments with drifted payload_preferences.id (missing sequence/default) were throwing ERROR: 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.

hassanthegooner avatar Oct 21 '25 14:10 hassanthegooner