Skip to content

Fix create_request crash when nothing is left to request - #486

Merged
felixschndr merged 2 commits into
joostlek:mainfrom
willmakenoise:fix-request-already-available
Nov 10, 2026
Merged

felixschndr merged 2 commits into
joostlek:mainfrom
willmakenoise:fix-request-already-available

Conversation

@willmakenoise

@willmakenoise willmakenoise commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

create_request() crashes with an opaque mashumaro.exceptions.MissingField error (Field "id" of type int is missing in RequestWithMedia instance) when there's nothing left to request — e.g. requesting a TV show where every season is already requested or available.

Root cause

Overseerr/Seerr's request route doesn't always create a MediaRequest. When none of the requested seasons can be requested, the server throws NoSeasonsAvailableError, which the route handler maps to an HTTP 202 with body {"status": 202, "message": "No seasons available to request"} instead of a created request (see server/routes/request.ts and server/entity/MediaRequest.ts).

A season counts as "existing" here if it has an open request (pending/approved, same 4K flag) or any media status other than UNKNOWN/DELETED, so this covers both "already requested" and "already available".

Since 202 is a 2xx status, _request() doesn't raise, so this response reaches RequestWithMedia.from_json(), which fails trying to parse a body with no id, media, requestedBy, etc.

(For comparison: a genuine duplicate request throws DuplicateMediaRequestError, mapped to a real HTTP 409, which _request() already handles correctly by raising OverseerrConnectionError.)

Fix

create_request() now parses the response once and checks for "status": 202 in the body. When present, it raises a new OverseerrNothingToRequestError with the server's own message. Otherwise the parsed dict is passed to RequestWithMedia.from_dict().

Testing

  • Added test_creating_request_nothing_to_request, with a new fixture (no_seasons_available.json, using the real message text from the server source) mirroring the existing overseerr/seerr fixture split.
  • Full suite, ruff format, pylint, and mypy all pass locally.

@felixschndr felixschndr added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Oct 28, 2026
@felixschndr

Copy link
Copy Markdown
Collaborator

Thanks for the PR!

However, I see a few things to do before merging:

  1. The Exception name doesn't match what the server does: NoSeasonsAvailableError isn't only thrown when seasons are available. In MediaRequest.ts (existingSeasons), a season counts as "existing" if it has an open request (pending/approved, same 4K flag) or any media status other than UNKNOWN/DELETED (e.g. pending, processing, partially available). So "already requested" hits this path just as often as "already available". Something like OverseerrNothingToRequestError would be more accurate.
  2. Detect the actual signal instead of "no id": Right now any 2xx body without id is reported as "media already available", which would mislabel any other unexpected response. The body carries "status": 202, so we can check that directly. Somethuing like
    response = await self._request(METH_POST, "request", data=data)
    parsed = orjson.loads(response)
    if parsed.get("status") == 202:
        raise OverseerrNothingToRequestError(
            parsed.get("message", "No request was created")
        )
    return RequestWithMedia.from_dict(parsed)
  3. Avoid parsing the body twice: orjson.loads + RequestWithMedia.from_json(response) parses the same payload twice. Since we already have the dict, we can use it RequestWithMedia.from_dict(parsed)

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.14%. Comparing base (6cc0c89) to head (2336b32).
⚠️ Report is 42 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #486      +/-   ##
==========================================
+ Coverage   99.10%   99.14%   +0.03%     
==========================================
  Files           4        4              
  Lines         448      469      +21     
  Branches       13       15       +2     
==========================================
+ Hits          444      465      +21     
  Misses          3        3              
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@willmakenoise

Copy link
Copy Markdown
Contributor Author

Thanks @felixschndr for the thorough review! All three points are addressed in 2336b32:

  1. Renamed the exception to OverseerrNothingToRequestError. You're right, existingSeasons covers open requests and non-UNKNOWN/DELETED media statuses too, so "already available" was too narrow.
  2. It now checks parsed.get("status") == 202 instead of the missing id, so other unexpected responses aren't mislabelled.
  3. It parses once and uses RequestWithMedia.from_dict(parsed).

I've also updated the PR description to match.

@felixschndr

Copy link
Copy Markdown
Collaborator

Looks good, thanks for the PR

@felixschndr
felixschndr merged commit 343e5ea into joostlek:main Nov 10, 2026
12 checks passed
@felixschndr

Copy link
Copy Markdown
Collaborator

I released this (https://github.com/joostlek/python-overseerr/releases/tag/v0.10.1). In case you are using it for Home Assistant, feel free to open a bump PR, I will merge this then, if not then not :)

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants