internetarchive / internetarchive/openlibrary
Pass request params as args in 6 helpers (FastAPI prep)
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 138
Description
## Problem / Opportunity
Handlers read request data with `web.input()`. Helpers also call `web.input()` deep in the code. This hidden global blocks FastAPI migration. FastAPI needs explicit params.
This issue tracks 6 helpers. Each helper must take explicit args. Handlers must pass the args down. This work makes later FastAPI conversion easy. It changes no behavior.
Audience: developers who migrate web.py handlers to FastAPI.
## Proposal
Change 6 helpers. Remove `web.input()` from each helper. Update callers to pass values. Keep behavior identical. Do not add new tests. Run existing tests only.
Tracked in 3 sub-issues (one PR each), linked below.
### Group 1 — Trivial prefs (no risk)
* `openlibrary/book_providers.py:756` `get_provider_order()` — read `?providerPref` in handler. Pass `provider_pref` as arg.
* `openlibrary/plugins/upstream/utils.py:1431` `get_ia_host()` — read `?dev_host` in handler. Pass `dev_host` as arg.
* `openlibrary/plugins/worksearch/code.py:321` `get_remembered_layout()` — read `?layout` and cookie in handler. Pass both as args.
### Group 2 — Security paths (needs care)
* `openlibrary/plugins/upstream/spamcheck.py:35` `is_spam()` — require `i` from caller. Remove `web.input()` fallback.
* `openlibrary/plugins/recaptcha/recaptcha.py:34` `validate()` — pass `g-recaptcha-response` and client IP as args. Keep `web.form.Validator` shim for web.py.
### Group 3 — High-traffic page
* `openlibrary/plugins/upstream/models.py:483` `Author.get_books()` — read `sort`, `page`, `rows`, `mode` in handler. Pass all 4 as args. Update `openlibrary/templates/type/author/view.html:23`.
## Breakdown
Implementation details for maintainers.
#### Related files
* `openlibrary/book_providers.py`
* `openlibrary/plugins/upstream/utils.py`
* `openlibrary/plugins/worksearch/code.py`
* `openlibrary/plugins/upstream/spamcheck.py`
* `openlibrary/plugins/recaptcha/recaptcha.py`
* `openlibrary/plugins/upstream/models.py`
* `openlibrary/templates/type/author/view.html`
* `openlibrary/templates/site/donation_banner.html`
* `openlibrary/templates/account/ia_thirdparty_logins.html`
Out of scope: `ListRecord.from_input()` (`openlibrary/plugins/openlibrary/lists.py:135`), framework processors, `changequery`, middleware, templates/macros port, coverstore. File that separately.
#### Requirements Checklist
* [ ] Group 1 done: 3 helpers take explicit args. No `web.input()` inside. Callers updated.
* [ ] Group 2 done: `is_spam` requires `i`. `validate` takes response and IP. Callers updated.
* [ ] Group 3 done: `get_books` takes `sort`, `page`, `rows`, `mode`. Template updated.
* [ ] No behavior change in any group.
* [ ] Existing tests pass (`make test-py-uv`). Do not add new tests.
* [x] 3 sub-issues exist: #13537, #13538, #13539. Each links to this epic.
#### Stakeholders
Lead: @RayBB.
Contributor guide
Research direction
Start with sub-issues #13537, #13538, and #13539 rather than taking this epic as one change. Read the six listed helper locations and their callers, then run `make test-py-uv`; done means each helper receives explicit request values, the author template is updated, and existing behavior and tests remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100