Skip to content

feat: migrate list_view_json endpoint to FastAPI#12556

Merged
RayBB merged 8 commits into
internetarchive:masterfrom
shoaib-inamdar:12487/feature/migrate-list-view-json-to-fastapi
May 8, 2026
Merged

feat: migrate list_view_json endpoint to FastAPI#12556
RayBB merged 8 commits into
internetarchive:masterfrom
shoaib-inamdar:12487/feature/migrate-list-view-json-to-fastapi

Conversation

@shoaib-inamdar

Copy link
Copy Markdown
Contributor

Migrates the list_view_json endpoint from web.py to FastAPI as part of issue #12487 (Migrate lists endpoints to FastAPI).

Changes:

  • openlibrary/fastapi/lists.py:

    • Add _get_list_or_404() helper that calls get_list() and raises HTTP 404 if the list is missing or has been deleted (/type/delete)
    • Add list_view_json_user() -> GET /people/{username}/lists/{list_id}.json
    • Add list_view_json_public() -> GET /lists/{list_id}.json
    • Add list_view_json_series() -> GET /series/{list_id}.json
    • All three routes accept ?_raw=true to return the raw DB record
    • Remove unused stale list_view_json() stub
  • openlibrary/plugins/openlibrary/lists.py:

    • Mark legacy list_view_json class with @deprecated('migrated to fastapi')
    • Fix import ordering: move typing_extensions to third-party group
  • openlibrary/tests/fastapi/test_list_view_json.py (new file):

    • 6 tests covering: user list, 404, deleted list, public list, series, and the ?_raw=true query param passthrough

Closes #12487

Technical

Testing

Screenshot

Stakeholders

@RayBB

Migrates the list_view_json endpoint from web.py to FastAPI as part of
issue internetarchive#12487 (Migrate lists endpoints to FastAPI).

Changes:
- openlibrary/fastapi/lists.py:
  - Add _get_list_or_404() helper that calls get_list() and raises
    HTTP 404 if the list is missing or has been deleted (/type/delete)
  - Add list_view_json_user()  -> GET /people/{username}/lists/{list_id}.json
  - Add list_view_json_public() -> GET /lists/{list_id}.json
  - Add list_view_json_series() -> GET /series/{list_id}.json
  - All three routes accept ?_raw=true to return the raw DB record
  - Remove unused stale list_view_json() stub

- openlibrary/plugins/openlibrary/lists.py:
  - Mark legacy list_view_json class with @deprecated('migrated to fastapi')
  - Fix import ordering: move typing_extensions to third-party group

- openlibrary/tests/fastapi/test_list_view_json.py (new file):
  - 6 tests covering: user list, 404, deleted list, public list,
    series, and the ?_raw=true query param passthrough
Copilot AI review requested due to automatic review settings May 3, 2026 18:19
@github-project-automation github-project-automation Bot moved this to Waiting Review/Merge from Staff in Ray's Project May 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the list_view_json endpoint from the legacy web.py implementation to FastAPI, continuing the repo’s incremental lists-endpoint migration for issue #12487. It adds FastAPI routes for user, public, and series list JSON views while keeping the shared list-fetching logic in the existing lists module.

Changes:

  • Added FastAPI *.json routes for user lists, public lists, and series lists, plus a shared _get_list_or_404() helper.
  • Reused the existing get_list() helper from openlibrary.plugins.openlibrary.lists and marked the legacy web.py endpoint as deprecated.
  • Added a new FastAPI test file covering basic success, missing-list, deleted-list, series/public variants, and _raw=true.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
openlibrary/fastapi/lists.py Adds the new FastAPI list-view routes and 404 helper logic.
openlibrary/plugins/openlibrary/lists.py Reuses/refactors legacy list retrieval and deprecates the old web.py endpoint class.
openlibrary/tests/fastapi/test_list_view_json.py Adds route-level tests for the migrated endpoint behavior.

return FAKE_LIST

monkeypatch.setattr("openlibrary.fastapi.lists.get_list", fake_get_list)
resp = client.get("/people/testuser/lists/OL123L.json?_raw=true")

def get_list(key: str, raw: bool = False) -> dict | None:
lst = web.ctx.site.get(key)
lst = site.get(key)
Comment thread openlibrary/fastapi/lists.py Outdated
def _get_list_or_404(key: str, raw: bool) -> dict:
"""Fetch a list by key and raise 404 if not found or deleted."""
lst = get_list(key, raw=raw)
if not lst or (not raw and lst.get("type", {}).get("key") == "/type/delete"):
@mekarpeles

Copy link
Copy Markdown
Member

Thanks for the PR, @shoaib-inamdar!

Copilot has been assigned for an initial review.

@RayBB is assigned to this PR and currently has:

  • 7 open PR(s) of equal or higher priority to review first

The linked issue (#12487) has not yet been triaged — triage happens on Mondays and Fridays.

Possible improvements for this PR

  • The Testing section in the PR body is empty (contains only the template placeholder). Please describe what you tested or verified — e.g. which endpoints you called, what responses you confirmed, or a note that the included unit tests were run and passed.
PR triage checklist (maintainers / Pam)
  • PR description — not empty; explains what the change does and how to verify it
  • References an issue — PR body contains a #NNN reference
    • Linked issue is triaged — has a Priority: * label (not just Needs: Triage)
    • Linked issue is assigned — has at least one assignee
  • Commit history clean — no WIP/fixup/conflict noise; commit messages are meaningful
  • CI passing — no failing check-runs
  • Test cases present — if the change touches substantive logic, test coverage exists or is explained
  • Proof of testing — PR body includes a description of what was tested, a screenshot, or a video

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.

@mekarpeles mekarpeles added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label May 3, 2026
mypy [union-attr] (25 errors):
- cast(List | None, site.get(key)) in get_list() to tell mypy the result
  is a List object (not str | Site); List is already imported from
  openlibrary.core.lists.model

copilot suggestion internetarchive#2 (lists.py):
- Already resolved: site.get(key) instead of web.ctx.site.get(key)

copilot suggestion internetarchive#3 (fastapi/lists.py):
- Use walrus operator in _get_list_or_404() to combine the get_list()
  call and None-check into one expression

copilot suggestion internetarchive#1 (test file):
- Capture and assert the key argument in test_list_view_json_raw_param
  to verify the correct list key is forwarded to get_list()
@shoaib-inamdar shoaib-inamdar force-pushed the 12487/feature/migrate-list-view-json-to-fastapi branch from 36efcd0 to b6c786f Compare May 3, 2026 18:52
@github-actions github-actions Bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label May 3, 2026
@RayBB

RayBB commented May 5, 2026

Copy link
Copy Markdown
Collaborator

@Sanket17052006 would you be willing to review/test this one thoroughly in your local env?

@Sanket17052006

Copy link
Copy Markdown
Contributor

Yes, I would like to give it a shot

@github-actions github-actions Bot added the Needs: Response Issues which require feedback from lead label May 6, 2026

@Sanket17052006 Sanket17052006 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @shoaib-inamdar, tested this locally — here's what I found.
master branch
curl "http://localhost:8080/people/openlibrary/lists/OL15L.json?_raw=true" returns 200 OK with correct JSON (tested with list OL15L - created locally for this review)
PR branch (8080)
curl "http://localhost:8080/people/openlibrary/lists/OL15L.json?_raw=true"
returns 500 AttributeError: 'Site' object has no attribute 'dict'
PR branch (port 18080)
curl "http://localhost:18080/people/openlibrary/lists/OL15L.json?_raw=true" returns Same AttributeError originating from fastapi/lists.py -> get_list
Root cause: The change from web.ctx.site.get(key) to site.get(key) in get_list is the problem as per my findings.
Also worth noting: once this is fixed, the ?_raw=true + deleted list case will need attention too. Happy to test after you input, and do point out if I missed out on something. :)

@shoaib-inamdar shoaib-inamdar force-pushed the 12487/feature/migrate-list-view-json-to-fastapi branch from 43e0f60 to b919341 Compare May 6, 2026 17:29
@shoaib-inamdar

Copy link
Copy Markdown
Contributor Author

@Sanket17052006 , i have fixed the issue

@Sanket17052006

Copy link
Copy Markdown
Contributor

@shoaib-inamdar the changes look good, but are you able to hit port 18080 successfully with ?_raw=true in your local setup? I'm still getting a 404 for a list that exists on port 8080, so want to make sure I'm not missing something in my env.
Any thoughts @RayBB

@Sanket17052006

Copy link
Copy Markdown
Contributor

@shoaib-inamdar sorry there was a bit confusion on my part, I’ve re‑tested after the latest fixes

  • Legacy endpoint (8080) returns 200 OK with correct JSON for an existing list.
  • FastAPI endpoint (18080) now returns the same 200 OK for the same list.
  • A non‑existent list returns 404 Not Found as expected.
  • The deleted‑list case with ?_raw=true also returns 404

@RayBB LGTM, can you take a look?

@RayBB RayBB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shoaib-inamdar and @Sanket17052006 thank you very much for submitting a high quality PR that was well tested.

I went ahead and pushed up some very small refactors to simplify things and ensure we support the /people/username/series case but overall this is very good.

Handles raw and 404 perfectly and has good validation.

Thanks for this!

@Sanket17052006 I hope you can rebase your PR off this one and follow similar patterns when it makes sense.

@RayBB RayBB merged commit d551e00 into internetarchive:master May 8, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting Review/Merge from Staff to Done in Ray's Project May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Migrate lists endpoints to fastapi

5 participants