Skip to content

Commit d810de3

Browse files
committed
fix: address code review feedback
- 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
1 parent da60a67 commit d810de3

File tree

3 files changed

+24
-47
lines changed

3 files changed

+24
-47
lines changed

litestar/_multipart.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ async def parse_multipart_form( # noqa: C901
133133
await data.close()
134134
await _close_upload_files(fields)
135135

136-
# FIXED (3.0): This now should raise a '413 - Request Entity Too Large'
137136
raise HTTPException(
138137
status_code=HTTP_413_REQUEST_ENTITY_TOO_LARGE,
139138
detail="Multipart form size limit exceeded")

tests/unit/test_data_extractors.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
from litestar import Request
88
from litestar.connection.base import empty_receive
99
from litestar.data_extractors import ConnectionDataExtractor, ResponseDataExtractor
10-
from litestar.datastructures import Cookie
10+
from litestar.datastructures import Cookie, UploadFile
1111
from litestar.enums import RequestEncodingType
1212
from litestar.response.base import ASGIResponse
13-
from litestar.status_codes import HTTP_200_OK
14-
from litestar.testing import RequestFactory
13+
from litestar.status_codes import HTTP_200_OK, HTTP_413_REQUEST_ENTITY_TOO_LARGE
14+
from litestar.testing import RequestFactory, create_test_client
15+
from litestar import post
16+
from litestar.params import Body
1517

1618
factory = RequestFactory()
1719

@@ -125,3 +127,22 @@ async def test_skip_parse_malformed_body_false_raises(mocker: MockFixture) -> No
125127

126128
with pytest.raises(ValueError):
127129
await extractor.extract(req, {"body"})
130+
131+
async def test_multipart_exceeds_part_limit_returns_413() -> None:
132+
@post("/upload")
133+
async def upload_handler(
134+
data: UploadFile = Body(media_type=RequestEncodingType.MULTI_PART)
135+
) -> dict:
136+
return {"filename": data.filename}
137+
138+
with create_test_client(route_handlers=[upload_handler], multipart_form_part_limit=2) as client:
139+
response = client.post(
140+
"/upload",
141+
files={
142+
"file1": ("test1.txt", b"content1"),
143+
"file2": ("test2.txt", b"content2"),
144+
"data": ("test3.txt", b"content3"),
145+
},
146+
)
147+
148+
assert response.status_code == HTTP_413_REQUEST_ENTITY_TOO_LARGE

tests/unit/test_multipart_413.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)