-
-
Notifications
You must be signed in to change notification settings - Fork 488
Open
Labels
Bug 🐛This is something that is not working as expectedThis is something that is not working as expected
Description
Description
# 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 NoneThe correct exception class RequestEntityTooLarge already exists in the codebase and is used elsewhere (e.g., in connection/request.py), but the multipart parser hasn't been updated to use it.
Impact:
- HTTP specification non-compliance
- Clients cannot properly differentiate between bad request format (400) and payload too large (413)
- Inconsistent error handling across the framework
Proposed Solution:
- Import
RequestEntityTooLargeinlitestar/_multipart.py - Replace
ClientException("Request Entity Too Large")withRequestEntityTooLarge - Update related tests to expect HTTP 413 instead of 400
- Mark as breaking change for v3.0 release notes
URL to code causing the issue
https://github.com/litestar-org/litestar/blob/main/litestar/_multipart.py#L136-L138
MCVE
## **MCVE:**ython
from litestarmport Litestar, postom litestar.dataploadFile
@post("/uploastructures import UploadFile
@post("/uploaoad_file(ata: UploadFile) -> dictstr, str]:
return {"}filename": data.filename}Litestar(rs=[upload_file
route_handlers=[upload_file_limitSet # Setow limit to trigger very low limit to trigger a file that exceeds the limit: uploading a file that exceeds the limit:havior: Returnscted behavior: Should Request
# Expected behavior: ShoulTP 413 RequestToo LargeSteps to reproduce
- Create a Litestar app with a file upload endpoint
- Set
multipart_form_part_limitto a low value (e.g., 1) - Upload a multipart form with more parts than the limit allows
- Observe the HTTP status code returned
- Current: Receives HTTP 400 (Bad Request)
- Expected: Should receive HTTP 413 (Request Entity Too Large)
Alternative reproduction:
- Navigate to
litestar/_multipart.pyline 136-138 - Observe the FIXME comment acknowledging this issue
- Note that
RequestEntityTooLargeexception already exists but is not used here
Screenshots
No response
Logs
# Current behavior when multipart limit is exceeded:
# HTTP/1.1 400 Bad Request
# {"detail": "Request Entity Too Large", "status_code": 400}
# Expected behavior:
# HTTP/1.1 413 Request Entity Too Large
# {"detail": "Request Entity Too Large", "status_code": 413}
Litestar Version
Latest main branch (as of October 2025)
This issue exists in the current main branch and is marked for fixing in version 3.0
per the FIXME comment in the source code.
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)
Metadata
Metadata
Assignees
Labels
Bug 🐛This is something that is not working as expectedThis is something that is not working as expected