Closed
Conversation
Changed ClientException to RequestEntityTooLarge when multipart request exceeds size limits, returning HTTP 413 status code instead of HTTP 400 per RFC 7231. Closes litestar-org#4439
Previously, when multipart form data exceeded the part limit, a ClientException (400) was raised. This fix properly raises RequestEntityTooLarge (413) when ParserLimitReached is caught. - Added RequestEntityTooLarge exception class - Updated parse_multipart_form to raise 413 on limit exceeded - Added test case to verify 413 status code
provinzkraut
requested changes
Nov 20, 2025
| PushMultipartParser, | ||
| ) | ||
|
|
||
| from litestar.utils.compat import async_next |
Member
There was a problem hiding this comment.
Why is this being imported here?
Author
There was a problem hiding this comment.
@provinzkraut I've addressed the feedback with one clarification:
I did not remove the except StopAsyncIteration: block. Removing it caused a runtime failure (NameError: name 'async_next' is not defined) and resulted in a 500 instead of the expected 413. Keeping the explicit exception handling ensures the correct 413 response is returned.
litestar/_multipart.py
Outdated
| # FIXME (3.0): This should raise a '413 - Request Entity Too Large', but for | ||
| # backwards compatibility, we keep it as a 400 for now | ||
| raise ClientException("Request Entity Too Large") from None | ||
| # FIXED (3.0): This now should raise a '413 - Request Entity Too Large' |
Member
There was a problem hiding this comment.
This comment isn't really useful. Please remove it
- Remove FIXED comment from exception handler - Move multipart 413 test to test_data_extractors.py following project conventions - Ensure test follows existing test suite patterns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the issue where exceeding multipart form part limits returned HTTP 400 instead of HTTP 413.
Changes
RequestEntityTooLargeexception tohttp_exceptions.py_multipart.pyto catchParserLimitReachedand raiseRequestEntityTooLargetest_oversized_file_returns_413to verify proper status codeTesting
Closes 4439