Skip to content

Deleting an instrument record leaves an orphaned session, and no endpoint can delete a session #1883

Open

Description

@gdevenyi

Problem

Deleting an instrument record leaves its session in the database, and no endpoint can delete a session.

  • InstrumentRecordsService.deleteById (apps/api/src/instrument-records/instrument-records.service.ts) deletes the record and its files only.
  • SessionsController has only POST /sessions and GET /sessions.
  • The only path that deletes sessions is DELETE /subjects/:id?force=true, which deletes the whole subject.

Every session created by the bulk upload or by a form holds exactly one record, so each record delete leaves an empty session. These sessions:

  • count toward GET /summary counts.sessions and its trend,
  • appear in the session list and the subject's session history,
  • cannot be removed by an admin without direct database access.

Observed

On a production instance (v2.5.2), a cleanup of about 26,000 duplicate bulk-uploaded records through DELETE /instrument-records/:id would leave about 26,000 empty sessions. Before any cleanup, that instance already has 79 sessions with no record.

Options

  1. In deleteById, also delete the record's session in the same transaction when no other record references it.
  2. Add DELETE /sessions/:id (@RouteAccess({ action: 'delete', subject: 'Session' })), rejected while the session still has records.
  3. Both.

Option 1 stops new orphans. Option 2 (or a one-off migration) is still necessary to remove the sessions that are already orphaned.

Activity

  1. added
    BugType: existing behavior is wrong
    Difficulty: MediumStraightforward change, about a day or less
    Area: APIapps/api (NestJS backend, Prisma models, CASL permissions)
    Needs DecisionWell-defined, but blocked on a maintainer decision about direction or design
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: APIapps/api (NestJS backend, Prisma models, CASL permissions)BugType: existing behavior is wrongDifficulty: MediumStraightforward change, about a day or lessNeeds DecisionWell-defined, but blocked on a maintainer decision about direction or designPriority: MediumReal value; schedule normally

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions