db-postgres: after reordering array rows, a row without a polymorphic relationship inherits the one stored in _rels at its new index

Aperta
#19,659 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@pcbeingused333 ci sta già lavorando.

Dal 17/11/2026.

  • #19687 di @pcbeingused333 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, typescript
Ambito
database

Direzione di ricerca

The issue identifies @payloadcms/drizzle's upsertRow as the affected entry point. Read how it updates positional paths in the Postgres _rels table, then reproduce the reorder with repro-5.ts against an empty PostgreSQL database. It is done when the saved _rels rows contain only relationships present in the data and Login has no inherited reference.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug db-postgres (`@payloadcms/drizzle` `upsertRow`) Payload OSS
Describe the Bug

In the Postgres adapter, relationships inside arrays are stored in <table>_rels under positional paths (links.0.reference, links.1.reference). On update, upsertRow deletes the existing rels only for the paths it re-inserts. A row whose relationship is absent from the data never clears the rel at its index. In the reproduction, that is a polymorphic relationTo: ['notes'] field shown only for type: 'internal'. After a reorder, such a row inherits the relationship of the row that used to be at its position.

A single-collection relationTo: 'notes' is stored as a column on the array table, so it is not affected. Only relationships that go through _rels are affected: polymorphic ones, and presumably hasMany ones.

Expected: after the update, _rels holds only the relationships present in the saved data, and the moved row's reference is empty.

Link to the code that reproduces this issue

https://github.com/elghaied/payload-v4-reproductions (repro-5.ts)

Reproduction Steps
  1. pnpm install, then cp .env.example .env and point DATABASE_URL at an empty PostgreSQL database
  2. pnpm repro repro-5.ts

The script creates a menu with [First (internal, reference → a note), Login (external, no reference)], then saves [Login, First] with the same ids, First keeping its reference. Output:

menus_rels rows: [{"path":"links.0.reference","notes_id":3},{"path":"links.1.reference","notes_id":3}]
observed Login.reference: { relationTo: 'notes', value: 3 }  expected: null/undefined
Which area(s) are affected?

db-postgres (@payloadcms/drizzle upsertRow)

Environment Info
payload: 4.0.0-beta.9
@payloadcms/db-postgres: 4.0.0-beta.9
Node.js: 24.22.1
PostgreSQL: 17.10
(local API only, no Next.js app)
Lingua principale
TypeScript
Stelle
45.8k
Fork
4.4k
Merge medio
2g 16h
PR unite (30g)
251

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di payloadcms/payload

Tutte le issue di payloadcms/payload

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.