Repository navigation
Conversation
|
Thanks for the PR, @Sanket17052006! A reviewer must first be assigned. There are currently 124 open PRs of equal or higher priority ahead of yours. PR triage checklist (maintainers / Pierre)
Note This comment was automatically generated by Pierre, Open Library's PR first-touch assistant, on behalf of @mekarpeles. This is NOT a code review or sign-off. |
006d518 to
6856575
Compare
work_id values like "abc", "OLxyzW" or "" raised ValueError/IndexError while parsing and returned 500 (master too). Validate the parameter as a numeric work ID or work OLID so bad input gets a 422.
The removed tests asserted exact SQL strings or substrings, or exercised get_awards_sync through a fake async_bridge; the Postgres integration test runs the same queries for real (and now also checks get_count with an OLID). Keep the concurrent-conflict recheck test, which the integration test can't reach, and test_remove_requires_a_filter.
Work.get_awards, Work.check_if_user_awarded and Work.get_award_by_username have no callers anywhere (Python, templates, macros, JS), and they were the only users of the new get_awards_sync bridge. Drop all four.
Resolve the Bookshelves.user_has_read_work conflict with internetarchive#14069: keep it async (its only caller, Bestbook._check_award_conditions, awaits it) and use the single-work get_users_read_status_of_work that master now has, instead of going through the batch method. Drop the unit test that patched the batch method; the bestbook integration test covers both branches against Postgres.
One test file per module: the Bestbook model's unit and Postgres integration tests live in tests/core/test_bestbook.py, not a separate _async file.
RayBB
left a comment
There was a problem hiding this comment.
Thanks @Sanket17052006, this is a clean migration! ON CONFLICT DO NOTHING plus re-validation is exactly right: 30 identical award requests in parallel gave one row, 29 of the usual error messages and no 500s, and /awards/count.json now accepts OL123W (it 500'd on master). I pushed a few small commits on top: a 422 for malformed work_ids on the count endpoint, removed get_awards_sync and the three unused Work award helpers it served, merged master and made user_has_read_work use the new async get_users_read_status_of_work from #14069, trimmed the SQL-string unit tests the integration test covers, and moved the tests into test_bestbook.py. 🎉
Part of #13826
This PR migrates the Bestbook awards FastAPI paths to async database access.
Technical
get_count_syncbridge for its legacy caller (Work.resolve_redirect_chain); remove the unusedWork.get_awards,Work.check_if_user_awardedandWork.get_award_by_usernamehelpers rather than bridging them.work_id.POST /works/OL{id}W/awards.jsonnow also returns the new award'sawardid.Bookshelves.user_has_read_workis async and uses the single-workget_users_read_status_of_work.openlibrary/tests/core/test_bestbook.py(one test file per module).Testing
docker compose run --rm home pytest -q openlibrary/tests/fastapi/ -x— Passed: 648 tests.docker compose run --rm home pytest -q openlibrary/tests/core/test_bestbook.py openlibrary/tests/core/test_bookshelves.py openlibrary/tests/fastapi/test_bestbook.py openlibrary/tests/core/test_models.py— Passed; integration tests deselected by default.uv run --with-requirements requirements_test.txt pytest -q -m integration openlibrary/tests/core/test_bestbook.py openlibrary/tests/core/test_bookshelves.py— Passed: PostgreSQL integration tests.curl -i 'http://localhost:8080/awards/count.json?work_id=123'andcurl -i 'http://localhost:8080/awards/count.json?work_id=OL123W'— Passed: both returned HTTP 200.Screenshot
N/A
Stakeholders
@RayBB