Repository navigation
Description
Problem
Creating a list, or adding seeds to one, through the JSON API returns 500 Internal Server Error when a seed is invalid. A malformed request should get a 400.
There are two causes:
olid_to_key()inopenlibrary/utils/__init__.pylooks up the OLID suffix with{...}[olid[-1]]. An unknown suffix (OL1X) or a lowercase one (ol1w) raisesKeyError. Theif not typ: raise ValueError(...)line after it never runs.lists_json_post()inopenlibrary/fastapi/lists.pyonly catchesSpamListErrorandClientException. So even theValueErrors thatListRecord.normalize_input_seed()already raises on purpose ("Seed key cannot be empty","Invalid seed") become a 500.
_update_list_seeds() (the seeds.json POST endpoints) already turns ValueError into a 400, so only cause 1 affects it.
| Endpoint | Seed | Result on master |
|---|---|---|
POST /people/{username}/lists.json |
"OL1X", "ol1w" |
500 (KeyError) |
POST /people/{username}/lists.json |
"", {"foo": "bar"} |
500 (ValueError) |
POST /lists/{olid}/seeds.json (and the people/series variants) |
"OL1X" in add |
500 (KeyError) |
POST /lists/{olid}/seeds.json |
"" in add |
400 (already handled) |
Reproducing the bug
On master (d86043a), with a logged-in user:
curl -si -b cookies.txt -X POST http://localhost:8080/people/openlibrary/lists.json \
-H 'Content-Type: application/json' \
-d '{"name": "test", "seeds": ["OL1X"]}'- Expected: 400 with a message such as
Invalid olid: OL1X, and no list created. - Actual: 500.
I confirmed this with FastAPI's TestClient, the same way openlibrary/tests/fastapi/test_lists_json.py does. "OL1X" and "ol1w" raise KeyError, while "" and {"foo": "bar"} raise ValueError. None of them is handled. I did not try it on openlibrary.org, because that would create real lists.
Context
- Validation happens in
lists_json.process_seeds(), before anything is saved, so no partial data is written. The only problem is the status code. - This is the same kind of bug as Unknown
sortreturns 500 on /search.json, /subjects/*.json, /publishers/*.json and /search #13988 (an unknownsortraisedKeyErrorand returned 500).
Breakdown
-
olid_to_key(): raiseValueErrorfor an unknown suffix instead ofKeyError. Add a test. -
lists_json_post(): turnValueErrorinto a 400, the same way_update_list_seeds()already does. - Add tests to
openlibrary/tests/fastapi/test_lists_json.py(bad seed on create gives 400) andtest_list_seeds.py(bad seed inaddgives 400).
Files: openlibrary/utils/__init__.py, openlibrary/fastapi/lists.py, and their tests.
I'd like to work on this if it's accepted.
Activity
openlibrary-bot commentedon Dec 2, 2026
Thank you @akashdeep62992-star for submitting this issue!
Priority: *andLead: @*Context
Both root causes check out against current
master(d86043a):olid_to_key()does{...}[olid[-1]]and only checksif not typ:afterward — a dict lookup miss raisesKeyErrorbefore that check is ever reached, so it's effectively dead code.lists_json_post()catches onlySpamListErrorandclient.ClientException._update_list_seeds()(backing theseeds.jsonPOST endpoints) already catchesValueErrorand returns 400 — confirming the asymmetry described, and giving a direct template for thelists_json_post()fix.openlibrary/tests/fastapi/test_lists_json.pyandopenlibrary/tests/fastapi/test_list_seeds.pyboth already exist, matching the issue's suggested test locations.sortreturns 500 on /search.json, /subjects/*.json, /publishers/*.json and /search #13988 (open,Needs: Triage,Lead: @RayBB) is the samedict[key]→ uncaughtKeyError→ 500 pattern, inSearchScheme.process_user_sortinstead ofolid_to_key. No PR references either issue yet.Issue Assessment
openlibrary/utils/__init__.pyandopenlibrary/fastapi/lists.pyare the only places touching this, and both test files already exist at the paths given.)🔔 Stakeholders
@RayBB — FastAPI migration lead; this bug sits in the FastAPI
lists.pyrouter from the list/series seeds migration (#12753).Full triage checklist
Note
This comment was automatically generated by Richy, Open Library's issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.