Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

bug(api): [E_UNIQUE] tentrance - duplicate j_document_entrance on permanent merge delete

Aperta
#1,902 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, nodejs
Ambito
api

Direzione di ricerca

The failing call is TEntrance.addToCollection(mergeIntoId, 'documents', newDocuments) in api/controllers/v1/entrance/delete.js around line 259, which builds the document list for the permanent merge. Read how that list is assembled, then compare with the organization merge fix referenced in #1757 to see how already-linked documents are skipped. To reproduce, link one document to two entrances and call the permanent merge delete endpoint. Done when the merge returns success with no duplicate junction row; the partial-commit question is a separate issue.

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

Descrizione

Priority: Medium Production Type: Bug

Describe the bug
Permanently deleting an entrance while merging it into another (isPermanent=1&entityId=<target>) returned a 500 after 14.4 s. TEntrance.addToCollection(mergeIntoId, 'documents', newDocuments) tries to insert a j_document_entrance row for a document that is already linked to the target entrance, and Waterline reports a uniqueness violation. The merge code does not remove documents the target already has.

To Reproduce

  1. Link the same document to two entrances (A and B)
  2. DELETE /api/v1/entrances/A?isPermanent=1&entityId=B
  3. addToCollection fails on the duplicate pair.

Input Data

  • Endpoint: DELETE /api/v1/entrances/119655?isPermanent=1&entityId=25308
  • Request Body: none
  • URL/Query Parameters: isPermanent=1, entityId=25308
  • User: id 32181, groups Administrator, Moderator, User, Leader
  • Log line: Permanent merge entrance 119655: {"action":"merge","entranceId":119655,"mergeIntoId":25308,"locations":[],"descriptions":[],"riggings":[],"histories":[],"comments":[],"documents":[24390],"names":[275487],"cave":120704}

Expected behavior
Documents already linked to the surviving entrance are skipped (same approach as the organization merge in #1757), and the merge completes.

Error Details

  • Error Type: AdapterError: Would violate uniqueness constraint-- a record already exists with conflicting value(s).
  • Occurrences: 1 in this triage window (1 in the 30d retention)
  • Time Range: 2026-10-09T13:09:23Z
  • Representative Trace ID: 01a120c8-2040-7270-82e2-2ff4329c2951
  • Stack Trace:
AdapterError: Would violate uniqueness constraint-- a record already exists with conflicting value(s).
    at node_modules/waterline/lib/waterline/methods/add-to-collection.js:424:19
    (call site: api/controllers/v1/entrance/delete.js:259, TEntrance.addToCollection)

Front-end request record

  • Client: 37.69.231.57, Chrome 154 on Android 10
  • Duration: 14433 ms, response size [not captured]
  • Retry sequence on /api/v1/entrances/119655: 13:07:25 DELETE entityId=25308 200 (694 ms, soft delete), 13:09:23 DELETE isPermanent=1&entityId=25308 500 (14.4 s). No retry afterwards.

Partial-success check (separate defect)
Before the failing step, the controller runs earlier steps (see the lines above 259) before the failing call. delete.js does not wrap the sequence in a transaction, so steps preceding line 259 may be committed while the entrance still exists as soft-deleted. [open question]: run SELECT id, is_deleted FROM t_entrance WHERE id = 119655; and compare j_document_entrance for 119655 vs 25308 to see what was applied.

Additional context

  • Service: api/controllers/v1/entrance/delete.js:259
  • Model: tentrance (junction jdocumententrance)
  • DB Error Code: [not logged] (Waterline E_UNIQUE wrapped as AdapterError)
  • Related: #1572 (same junction, different cause: the PUT link endpoint), #1757 (same pattern fixed for organizations)
Lingua principale
JavaScript
Stelle
18
Fork
3
Merge medio
1g 56m
PR unite (30g)
41

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

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 GrottoCenter/grottocenter-api

Tutte le issue di GrottoCenter/grottocenter-api

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.