Describe the bug
I'll illustrate an example of expected behaviour using a pydantic.BaseModel
:
class SomeType(BaseModel):
some_attr: Annotated[str, Field(min_length=2)]
@post("/")
def endpoint(data: SomeType) -> SomeType:
return data
app = Litestar([endpoint], debug=True)
Then I curl* an invalid input and a pydantic_core._pydantic_core.ValidationError
is raised.
But if I change the SomeType
to this:
@dataclass(config=ConfigDict(validate_assignment=True))
class SomeType:
some_attr: Annotated[str, Field(min_length=2)]
There is no error raised, even with the same invalid input curl*
*curl command:
curl -X 'POST' \
'http://127.0.0.1:8000/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"some_attr": "s"
}'
Environments (please complete the following information):
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too