Skip to content

skip orphan cars in piece metadata lookup#662

Merged
parkan merged 1 commit intomainfrom
fix/piece-metadata-orphan-cars
Apr 16, 2026
Merged

skip orphan cars in piece metadata lookup#662
parkan merged 1 commit intomainfrom
fix/piece-metadata-orphan-cars

Conversation

@parkan
Copy link
Copy Markdown
Collaborator

@parkan parkan commented Apr 16, 2026

Summary

  • GetMetadataHandler used .First(&car) which picks the oldest car row by PK. When multiple rows exist for the same piece_cid, older rows can have attachment_id = NULL (from ON DELETE SET NULL after a prior prep was deleted). The handler would return 404 "piece metadata not found" even though a valid, linked car row existed.
  • /piece/:id (findPiece) iterates all cars and skips those with nil AttachmentID, so the piece itself served correctly while metadata 404'd for the same CID.
  • Fix: filter the metadata lookup to attachment_id IS NOT NULL.

Test plan

  • New tests cover both the skip-orphan case (orphan + valid coexist → 200) and orphan-only (→ 404)
  • All three dialects (sqlite, mysql, postgres) pass in devcontainer
  • go vet + staticcheck clean

Car.AttachmentID is ON DELETE SET NULL (for fast prep deletion with
async cleanup). When a prep is deleted and re-created, the old car
rows survive with attachment_id = NULL while a new row gets created
for the same piece_cid. GetMetadataHandler used .First() which picks
the oldest row by PK -- an orphan -- and returned 404 even though a
valid row existed. findPiece already iterates past orphans; this
aligns the metadata lookup with that behavior.
@parkan parkan merged commit e51a848 into main Apr 16, 2026
1 check passed
@parkan parkan deleted the fix/piece-metadata-orphan-cars branch April 16, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant