Migrate lists_json GET/POST endpoints to FastAPI#12633
Conversation
|
Thanks for the contribution, @Shikhar-395! 🤖 Copilot has been assigned for an initial review. @RayBB is assigned to this PR and currently has:
PR triage checklist (maintainers / Pam)
Note This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting. |
There was a problem hiding this comment.
Pull request overview
This PR migrates the lists_json (aka .../lists.json) endpoints from legacy web.py to FastAPI while delegating the core behavior to the existing legacy handler logic via newly extracted helpers.
Changes:
- Added FastAPI
GETroutes forpeople,books,works,authors, andsubjectslists.jsonendpoints and a FastAPIPOSTroute for creating/people/{username}/lists.json. - Extracted
get_lists_json_doc,get_lists_json_data, and_changequeryhelpers from the legacylists_jsonhandler to support FastAPI context bridging. - Added FastAPI tests covering pagination clamping, 404/403 cases, spam detection, and
ClientExceptionhandling.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
openlibrary/fastapi/lists.py |
Implements FastAPI GET/POST handlers for .../lists.json, delegating to legacy list logic and formatting responses as JSON. |
openlibrary/plugins/openlibrary/lists.py |
Adds reusable helper functions extracted from the legacy handler to allow FastAPI to call into the existing logic. |
openlibrary/tests/fastapi/test_lists.py |
Adds tests for the new FastAPI lists.json behavior and error handling. |
|
Converting this to a draft until it’s passing the pre-commit checks and the merge conflicts are resolved. |
|
@Shikhar-395 you'll also need to rebase or merge master now that the first PR for this file was merged. |
…ists-json-to-fastapi # Conflicts: # openlibrary/fastapi/lists.py # vendor/infogami
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
RayBB
left a comment
There was a problem hiding this comment.
@Shikhar-395 the tests are still failing. You can look at some of the other recent PRs on this file to see how changquery was dealt with and to get a better idea of the basic patterns we want to follow. Tag me when you're ready for review.
If you don't want to keep working on this let me know as well.
RayBB
left a comment
There was a problem hiding this comment.
Great work here.
Tested endpoints:
https://openlibrary.org/people/raybb/lists.json
https://openlibrary.org/books/OL24764889M/lists.json
https://openlibrary.org/works/OL5734718W/lists.json
https://openlibrary.org/authors/OL1394244A/lists.json
https://openlibrary.org/subjects/fiction/lists.json
Offset and limit are also working as expected.
Also the post request is working.
I did go ahead and simplify the code quite a bit and split out the endpoints so the openapi spec is more useful (doesn't have tones of params not needed for each endpoint).
|
@Shikhar-395 again, great work here. Thanks for you help and please review the changes to learn from them! |
Part of #12487 (partial —
lists_jsononly)Summary
lists_jsonGET (people, books, works, authors, subjects) and POST endpoints from web.py to FastAPI, delegating to legacy handlersget_lists_json_data,get_lists_json_doc, and_changequeryhelpers from the legacy class to support FastAPI context bridgingClientExceptionhandlingStakeholder
@RayBB