fix(api): POST /api/requests/manual was unreachable - #235
Open
JediBrooker wants to merge 1 commit into
Open
JediBrooker wants to merge 1 commit into
JediBrooker wants to merge 1 commit into
Conversation
The route is declared after POST /{asin_or_uuid}, and FastAPI matches in
declaration order, so the catch-all claims it. Creating a manual request over
the API is treated as a request for a book with the ASIN "manual", which is
then looked up on Audible and answered with 404:
Failed to fetch book details from Audible asin=manual
2 validation errors for AudibleSingleResponse
product.release_date Field required
product.title Field required
The web UI is unaffected because it imports create_manual_request and calls it
directly rather than going over HTTP, which is likely why this went unnoticed.
Moves the handler and its request model above the catch-all, with a note so it
does not drift back. POST /{asin_or_uuid} still routes to create_request.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
POST /api/requests/manualis unreachable. It is declared afterPOST /{asin_or_uuid}, and FastAPI matches routes in declaration order, so the catch-all claims it and treatsmanualas an ASIN.Reproducing
Against
main, with any valid API key:and in the log:
It is hitting
create_requestwithasin_or_uuid="manual"and asking Audible for a book called "manual".The web UI is unaffected, because
app/routers/pages/search/manual.pyimportscreate_manual_requestand calls the function directly rather than going over HTTP. So only the REST endpoint is broken, which is probably why it has not come up.Same class of problem applies only to this one route.
GET /manualis fine because there is no bareGET /{asin_or_uuid}, andDELETE /manual/{id}andPATCH /manual/{id}/downloadedare fine because they have more path segments than the catch-alls they sit near.The change
Moves
ManualRequestand thePOST /manualhandler abovePOST /{asin_or_uuid}, with a comment so it does not drift back. No behaviour changes beyond the route becoming reachable.After:
The diff looks larger than it is: it is the same block of code moved, not rewritten.
Checked
uv run basedpyright— cleanuv run ruff format --check app— cleanjust test_format,just test_jinja— cleanuv run alembic check— no new operations (no schema change here)TestClientboth before and after: 404 before, 201 and a storedManualBookRequestafter, with the catch-all still reachingcreate_requestWritten with AI assistance; the reproduction above was run against unmodified
main.