Skip to content

fix(litestar): apply Litestar's request_max_body_size default - #164

Merged
lesnik512 merged 4 commits into
mainfrom
fix/litestar-request-max-body-size
Aug 10, 2026
Merged

fix(litestar): apply Litestar's request_max_body_size default#164
lesnik512 merged 4 commits into
mainfrom
fix/litestar-request-max-body-size

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Stacked on #163, which carries the change file. Review that first, or read this diff alone — it is four commits of code and docs.

LitestarBootstrapper builds its app with Litestar.from_config(), which passes every AppConfig field explicitly, so the 10 MB request_max_body_size default that Litestar(...) applies never reached the built app. Every handler taking a request body returned 500: 'request_max_body_size' set to 'Empty' on all layers unless the caller set the field themselves.

_apply_config now fills it when the field is Empty; a caller's own value, including an explicit None for no limit, is untouched and now proven enforced by a 413 test. A guard test pins the constant against Litestar's own __init__ signature default, so an upstream change fails CI instead of drifting.

Design and rationale: planning/changes/2026-08-10.03-litestar-request-max-body-size.md. Upstream: litestar#4296.

Also here, both surfaced by review:

  • The litestar extra floor moves from >=2.9 to >=2.15. AppConfig.request_max_body_size was added in 2.13.0 and litestar.middleware.ASGIMiddleware — already subclassed by the OTel middleware before this branch — in 2.15.0, both verified by installing those versions. The declared floor was already unsupported.
  • The access-logging tests drop the request_max_body_size=1000 workaround they were carrying for this defect.

Promoted into architecture/bootstrappers.md, documented in docs/integrations/litestar.md, and added to planning/releases/1.4.0.md.

🤖 Generated with Claude Code

Base automatically changed from docs/deferred-litestar-logging-defects to main August 10, 2026 17:31
Litestar.from_config() passes every AppConfig field explicitly, so the 10 MB
default Litestar.__init__ applies never reached a bootstrapped app and every
body-reading handler returned 500. Fill the field in _apply_config when it is
Empty, leaving a caller's own value (including an explicit None) alone.
The access-logging tests no longer need request_max_body_size on their handler
now that the bootstrapper fills the default.
Two independently verified gaps in the declared >=2.9 floor:
AppConfig.request_max_body_size, which LitestarBootstrapper._apply_config
now reads, was added in litestar 2.13.0 (absent in 2.12.0) -- on an older
litestar the attribute access raises AttributeError. Separately,
litestar.middleware.ASGIMiddleware, which LitestarOpenTelemetryInstrumentationMiddleware
already subclasses, was added in 2.15.0 (absent in 2.13 and 2.14) -- a
pre-existing mismatch for anyone on the OTel path with litestar 2.9-2.14.
Both confirmed by installing the relevant versions and inspecting their source.
Add a docs/integrations/litestar.md section (modeled on the Prometheus
one) explaining that Litestar.from_config() skips the request_max_body_size
default, that the bootstrapper fills it when AppConfig leaves it unset, and
how to override it (including None for no limit), with a link to the
upstream issue.

Fix an imprecise sentence in architecture/bootstrappers.md: Litestar's
attach thunk wraps _apply_config, it is not _apply_config itself.

Strengthen test_litestar_bootstrap_keeps_explicit_request_max_body_size to
prove the caller's limit is enforced, not just stored: it now posts an
oversized body to a handler and asserts Litestar's actual 413 response,
alongside the existing readback of the configured value.
@lesnik512
lesnik512 force-pushed the fix/litestar-request-max-body-size branch from 83ed86b to 77ac3b9 Compare August 10, 2026 17:32
@lesnik512
lesnik512 merged commit 679f287 into main Aug 10, 2026
11 checks passed
@lesnik512
lesnik512 deleted the fix/litestar-request-max-body-size branch August 10, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant