Migrate browse endpoint to FastAPI#12006
Conversation
65bf9dd to
8b17920
Compare
RayBB
left a comment
There was a problem hiding this comment.
It's a good start, but you need to follow the best practices per the comment I left.
|
Look in the models.py
…On Wed, Mar 4, 2026, 3:14 PM Sanket Srivastava ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In openlibrary/fastapi/internal/api.py
<#12006 (comment)>
:
> +async def browse(q: str = "", page: int = 1, limit: int = 100, subject: str = "", sorts: str = "") -> JSONResponse:
+ """Browse endpoint (migrated from openlibrary.plugins.openlibrary.api)."""
+ sorts_list = sorts.split(",")
+
Hey @RayBB <https://github.com/RayBB>, I have made the requested changes
but I couldn't locate where the parse_comma_separated_list function is
defined, guide me.
—
Reply to this email directly, view it on GitHub
<#12006 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHA5AJHGIO3RUYQ7DWBF5L4PC2F7AVCNFSM6AAAAACWGJWBN6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTQOJSGU4DGMZWGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Hey @RayBB , I think the |
RayBB
left a comment
There was a problem hiding this comment.
Sorry for the delay in feedback. It's a good start!
I understand this one is tricky because it can't be tested locally.
In this case, I think it's best to just return the exact same thing and not try to form it into a special response object.
openlibrary/fastapi/internal/api.py
Outdated
| response_model_exclude_none=False, | ||
| ) | ||
| async def browse(request: Annotated[BrowseRequest, Depends()], pagination: Annotated[Pagination, Depends()]) -> BrowseResponse: | ||
| """Browse endpoint (migrated from openlibrary.plugins.openlibrary.api).""" |
There was a problem hiding this comment.
Please add a short description of what it does
openlibrary/fastapi/internal/api.py
Outdated
| if not url: | ||
| works = [] | ||
| else: | ||
| works = await asyncio.to_thread(lending.get_available, url=url) |
There was a problem hiding this comment.
We don't want to put this on a thread. Generally we should avoid doing that. In this case it doesn't work on testing and it's hard to see the errors when it's on a thread.
openlibrary/fastapi/internal/api.py
Outdated
| if isinstance(works, list): | ||
| for work in works: | ||
| if isinstance(work, str) and (work.lower() == "error" or not work): | ||
| continue | ||
|
|
||
| if isinstance(work, str): | ||
| processed_works.append(WorkModel(key=work)) | ||
| elif hasattr(work, "dict"): | ||
| processed_works.append(WorkModel(**work.dict())) | ||
| elif isinstance(work, dict): | ||
| if work.get("key") == "error": | ||
| continue | ||
| processed_works.append(WorkModel(**work)) | ||
| elif hasattr(work, "key"): | ||
| processed_works.append(WorkModel(key=work.key)) |
There was a problem hiding this comment.
Why do we need to do this? I don't see anything similar in the old endpoint.
for more information, see https://pre-commit.ci
9e50d64 to
47aa052
Compare
|
Thanks @RayBB for the review! I have removed the threading and those messy if-else checks. Do the changes look good? |
RayBB
left a comment
There was a problem hiding this comment.
Great job on this on. I think it's exactly what we need.
I put it on testing and tested with this url and quite a few others and it works perfectly.
|
Thanks @RayBB , for those detailed reviews and looking forward to any suitable tasks you have for me. :) |
|
@Sanket17052006 would you like to migrate the public_observations endpoint as well now? |
Related to #11999
This PR migrates the browse endpoint from web.py to FastAPI.
Changes Made :-
openlibrary/fastapi/internal/api.py- Added the FastAPI browse endpoint.openlibrary/plugins/openlibrary/api.py- Deprecated the web.py endpoint.Testing
Test command -
./tests/integration/temporary/test_browse_migration.sh http://localhost:8080 http://localhost:18080Stakeholders
@RayBB