Bulk record upload inserts rows that already exist or repeat within the file, silently duplicating data

Aperta
#1,884 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à
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
18/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
react, typescript

Direzione di ricerca

Start in InstrumentRecordsService.upload, which handles POST /instrument-records/upload, and read the single-record POST /instrument-records path beside it. The issue asks for a decision first: reject with a 409 or skip duplicates and report counts, and whether to store a content hash on the record. Confirm that choice with maintainers before coding. Done means duplicate rows are detected on the server, with unit and e2e tests, and the web upload shows the counts before submit.

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

Descrizione

Area: API Area: Web Bug Difficulty: Medium Needs Decision Priority: High

Problem

POST /instrument-records/upload (InstrumentRecordsService.upload) inserts every row it receives. It does not check:

  • for rows repeated inside the same request, or
  • for rows that already exist (same subject, instrument, date and data).

So if a user uploads the same CSV again, or the browser sends the request again, all data is silently doubled. Nothing tells the user that the rows were already present.

Observed

A production instance (v2.5.2) holds 28,177 MOUSE_WEIGHT_FORM records that contain only 1,317 unique measurements for 402 subjects:

  • 7 upload batches over two days (2024-12-04 and 2025-01-07) put the same file in again, both in a group and with no group.
  • Inside one batch of 3,520 rows, 1,100 measurements occur 3 times, a few seconds apart. Either the CSV had repeated rows, or the request was sent again.
  • Each duplicate also has its own session (see the companion issue about deleting sessions).

About 38 smaller groups of exact duplicates come from forms submitted twice a few minutes apart.

Proposal (needs decision)

  • Server: before insert, find the existing records that match (subjectId, instrumentId, date, canonical JSON of data) and the matching rows inside the batch. Then either reject the request with a 409 that lists them, or skip them and return a count of created and skipped rows. A content hash stored on the record would make this an indexed lookup.
  • Web: show "N rows already exist, M rows repeated in the file" before the submit, with an explicit choice. The current page hides the form while the upload runs, but the server must not depend on the client for this.
  • The single-record POST /instrument-records may need the same guard against a double submit (a short time window, or an idempotency key).

Each change needs a unit test and an e2e test.

Lingua principale
TypeScript
Stelle
119
Fork
19
Merge medio
1g 18h
PR unite (30g)
61

Preparare l'ambiente

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 DouglasNeuroInformatics/OpenDataCapture

Tutte le issue di DouglasNeuroInformatics/OpenDataCapture

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.