Description
The vibe coded fix for #4647 doesn't completely fix the problem, it doesn't work for fields that get renamed by msgspec.Struct.
It could also be a deeper issue with litestar not handling renamed fields correctly, haven't checked
URL to code causing the issue
No response
MCVE
import msgspec
from typing import Optional, Annotated
from litestar import Litestar, get, post, Response
from litestar.datastructures import UploadFile
from litestar.params import Body
from litestar.enums import RequestEncodingType
# the rename="camel" is important
class Foo(msgspec.Struct, rename="camel"):
some_file: Optional[UploadFile] = None
@get("/")
async def foo() -> Response:
return Response("""\
<!DOCTYPE html>
<html>
<form action="/" method="post" enctype="multipart/form-data">
<input type="string" name="text"/><br/>
<input type="file" name="someFile"/><br/>
<input type="submit"/>
</form>
</html>
""", media_type="text/html")
@post("/")
async def bar(data: Annotated[Foo, Body(media_type=RequestEncodingType.MULTI_PART)]) -> str:
return f"ok, file is {data.some_file}"
app = Litestar(route_handlers=[foo, bar])
Steps to reproduce
- install litestar[standard] and run the app
- do not upload a file, just click submit
- Receive error
{"status_code":400,"detail":"Validation failed for POST /","extra":[{"message":"Unsupported type: <class 'str'>","key":"someFile","source":"body"}]}
Screenshots
No response
Logs
Litestar Version
2.17.0 doesn't have the bug, all later versions do (tested with 2.24 and 2.22)
Platform
Description
The vibe coded fix for #4647 doesn't completely fix the problem, it doesn't work for fields that get renamed by msgspec.Struct.
It could also be a deeper issue with litestar not handling renamed fields correctly, haven't checked
URL to code causing the issue
No response
MCVE
Steps to reproduce
{"status_code":400,"detail":"Validation failed for POST /","extra":[{"message":"Unsupported type: <class 'str'>","key":"someFile","source":"body"}]}Screenshots
No response
Logs
Litestar Version
2.17.0 doesn't have the bug, all later versions do (tested with 2.24 and 2.22)
Platform