Skip to content

fix: leave the audiobook file size out of full-row reads so GET /api/requests stops returning 500 - #609

Merged
kikootwo merged 2 commits into
mainfrom
fix/600-file-size-bigint
Nov 16, 2026
Merged

kikootwo merged 2 commits into
mainfrom
fix/600-file-size-bigint

Conversation

@kikootwo

@kikootwo kikootwo commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • The Prisma client now omits Audiobook.fileSizeBytes from every audiobook result, next to the existing libraryAsin omit (src/lib/db.ts). A query that needs the column selects it or sets omit: { fileSizeBytes: false }.
  • GET /api/requests/:id keeps returning audiobook.fileSizeBytes for both shapes: the non-admin field list already selects it, and the admin include now sets omit: { fileSizeBytes: false }. That route already converts BigInt values with toJsonSafe().
  • Tests: tests/services/db-omit-audiobook-columns.test.ts (renamed from db-omit-library-asin.test.ts) expects both columns in the client omit and checks that both detail shapes still read the file size; the admin include assertion in tests/api/request-display-library-asin.test.ts follows the new shape.
  • Docs: backend/services/api-tokens.md (GET /api/requests/:id returns 500 FetchError for any request that has a selected download #261 entry, and the request responses now list audiobook.fileSizeBytes among the fields left out) and backend/database.md note the omit.

Why

Audiobook.fileSizeBytes is a BigInt. GET /api/requests includes the whole audiobook row, so once a row holds a size, NextResponse.json throws Do not know how to serialize a BigInt and the request list never loads. About nine other routes include the full audiobook row the same way, plus the retry-download job payload. Omitting the column at the client covers all of them in one place. The only reader that wants the value, the request detail route, asks for it explicitly and converts it.

#600 proposed wrapping the list response in toJsonSafe(). With the column omitted that wrap has nothing left to convert (the list rows hold no other BigInt), so this change leaves the route as it is.

Checks

  • New and updated tests fail before the change (3 failures) and pass after it.
  • npx vitest related --run on the changed source and test files: passing.
  • npx tsc --noEmit: clean.
  • ESLint on the changed files: clean.
  • Every source reader of fileSizeBytes uses an explicit select: the request detail query; the only write sets it to null (reported-issue replace). The Library API and the library view loader select their own field lists and never read it.

Risk and rollback

  • Low. Full-row audiobook reads lose a column that nothing in the app reads from them; the request detail response is unchanged.
  • Rollback: revert this commit.

Found and diagnosed by @devinvee in #600.

Supersedes #600

🤖 Generated with Claude Code

kikootwo and others added 2 commits November 15, 2026 18:59
The Prisma client now omits Audiobook.fileSizeBytes, a BigInt, from every
audiobook result, next to the libraryAsin omit. GET /api/requests and the
other routes that include the whole audiobook row no longer hand a BigInt to
NextResponse.json, so the request list loads when a row holds a file size.
GET /api/requests/:id still returns the size for both shapes (non-admin
select, admin omit override) through toJsonSafe().

Found and diagnosed by @devinvee in #600.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kikootwo
kikootwo marked this pull request as ready for review November 16, 2026 00:12
@kikootwo
kikootwo merged commit 9d8ace9 into main Nov 16, 2026
1 check passed
@kikootwo
kikootwo deleted the fix/600-file-size-bigint branch November 16, 2026 00:23
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