8000 fix: thumbnail cache miss response and job re-queue logic by tamzrod · Pull Request #111 · tamzrod/Librarian · GitHub
[go: up one dir, main page]

Skip to content

fix: thumbnail cache miss response and job re-queue logic - #111

Merged
tamzrod merged 1 commit into
mainfrom
fix/thumbnail-cache-miss-response
Jul 6, 2026
Merged

tamzrod merged 1 commit into
mainfrom
fix/thumbnail-cache-miss-response

Conversation

@tamzrod
@tamzrod tamzrod commented Jul 6, 2026
Copy link
Copy Markdown
Owner

Summary

Fixed the thumbnail endpoint to return a valid placeholder image on cache miss instead of throwing HTTP 500.

Root Cause

The _get_thumbnail_placeholder() function was using FileResponse(io.BytesIO(...)) which is invalid because FileResponse requires a filesystem path, not a BytesIO object.

This caused:

TypeError: stat: path should be string, bytes, os.PathLike or integer, not BytesIO

Fix

Replaced FileResponse with fastapi.responses.Response which can serve in-memory bytes directly.

Changes

  • api/app.py: Changed import from FileResponse to Response
  • api/app.py: Updated _get_thumbnail_placeholder() to return Response(content=PLACEHOLDER_JPEG, media_type="image/jpeg")

Testing

The fix was verified to produce:

  • Status code: 200
  • Media type: image/jpeg
  • Valid JPEG placeholder bytes (149 bytes)

API Contract

This fix restores the intended cache-miss behavior for the thumbnail endpoint:

  1. Queue regeneration (if enabled) ✅
  2. Return HTTP 200 ✅
  3. Return a valid placeholder JPEG ✅
  4. Never return HTTP 500 ✅

@tamzrod can click here to continue refining the PR

Starlette FileResponse requires a filesystem path, not BytesIO.
This caused TypeError on cache miss when serving placeholder image.

Fix: Use fastapi.responses.Response which can serve in-memory bytes directly.
@tamzrod
tamzrod marked this pull request as ready for review July 6, 2026 23:22
@tamzrod
tamzrod merged commit ea31ed1 into main Jul 6, 2026
3 of 7 checks passed
@tamzrod tamzrod changed the title fix: use Response instead of FileResponse for thumbnail placeholder fix: thumbnail cache miss response and job re-queue logic Jul 6, 2026
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.

2 participants

0