Skip to content

Bug: TypeError: Using a non-empty mutable collection as a default value is unsafe on Python 3.14 #7

@roebi

Description

@roebi

Bug: TypeError: Using a non-empty mutable collection as a default value is unsafe on Python 3.14

Describe the bug

apiup starts and prints the banner but crashes when Litestar registers the route handlers.

Steps to reproduce

pipx install apiup
apiup

Error

TypeError: Using a non-empty mutable collection ({'_mock': True, 'status': 200,
'note': 'no example in spec'}) as a default value is unsafe. Instead configure
a `default_factory` for this field.

Root cause

In server.py, route handlers were defined with mutable dict default arguments:

async def _handler(b: Any = _body, s: int = _status) -> Any:
    ...

Litestar introspects handler signatures at registration time. On Python 3.14 this raises TypeError when a default value is a non-empty mutable collection.

Fix

Replace default-argument pattern with a _make_handler() closure factory at module level. The body and status code are captured in the closure — no default arguments, no mutable defaults. Body is also pre-serialised to bytes so Litestar never inspects the dict.

Environment

  • Python 3.14.3
  • apiup 0.2.0
  • litestar latest
  • Fedora Silverblue

Labels

bug

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions