Skip to content

Invalid list seeds return 500 on POST /people/{username}/lists.json and /lists/{olid}/seeds.json #14859

Backlog

Description

@akashdeep62992-star

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:

  1. olid_to_key() in openlibrary/utils/__init__.py looks up the OLID suffix with {...}[olid[-1]]. An unknown suffix (OL1X) or a lowercase one (ol1w) raises KeyError. The if not typ: raise ValueError(...) line after it never runs.
  2. lists_json_post() in openlibrary/fastapi/lists.py only catches SpamListError and ClientException. So even the ValueErrors that ListRecord.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

Breakdown

  • olid_to_key(): raise ValueError for an unknown suffix instead of KeyError. Add a test.
  • lists_json_post(): turn ValueError into 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) and test_list_seeds.py (bad seed in add gives 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

  1. added
    Needs: Triage
    Theme: Lists
    Theme: Public APIs
    Affects: Server
    on Dec 2, 2026
  2. openlibrary-bot commented on Dec 2, 2026

    @openlibrary-bot
    Collaborator

    Thank you @akashdeep62992-star for submitting this issue!

    ⚠️ Contributors, this issue will be ready to work on once:

    • Triage — maintainers will add Priority: * and Lead: @*

    Context

    Both root causes check out against current master (d86043a):

    • olid_to_key() does {...}[olid[-1]] and only checks if not typ: afterward — a dict lookup miss raises KeyError before that check is ever reached, so it's effectively dead code.
    • lists_json_post() catches only SpamListError and client.ClientException.
    • _update_list_seeds() (backing the seeds.json POST endpoints) already catches ValueError and returns 400 — confirming the asymmetry described, and giving a direct template for the lists_json_post() fix.
    • openlibrary/tests/fastapi/test_lists_json.py and openlibrary/tests/fastapi/test_list_seeds.py both already exist, matching the issue's suggested test locations.
    • Unknown sort returns 500 on /search.json, /subjects/*.json, /publishers/*.json and /search #13988 (open, Needs: Triage, Lead: @RayBB) is the same dict[key] → uncaught KeyError → 500 pattern, in SearchScheme.process_user_sort instead of olid_to_key. No PR references either issue yet.

    Issue Assessment

    • Are the suggested files correct? (Answer: yes — openlibrary/utils/__init__.py and openlibrary/fastapi/lists.py are 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.py router from the list/series seeds migration (#12753).


    Full triage checklist
    • Triage — correct labels applied or removed
    • Problem / opportunity — problem is clear, audience identified, actionable
    • Scope — issue is well-scoped; does not try to do too many things
    • Justification — reasoning and impact stated; sufficient for leads to prioritize
    • Success & testing criteria — defines what "done" looks like, verifiable by a contributor
    • Proposal & breakdown — concrete plan present; checklist actionable for a contributor
    • If bug: environment & repro steps — browser, version, local vs prod; steps to reproduce
    • Risks, concerns, open questions — identified and surfaced
    • Richy context — relevant code, commits, PRs reviewed; no duplicate found
    • References — screenshots, designs, docs, and links present where needed

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Affects: ServerModule: FastAPINeeds: LeadNeeds: TriageTheme: ListsTheme: Public APIs

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions