-
-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: beanie.PydanticObjectId cannot be a path parameter anymore #2158
Comments
Hi, have you tried defining a type decoder for the beanie type? |
No, how? I don't see a Also why I have to do something extra? The beanie type validates strings already: In [1]: from beanie import PydanticObjectId
In [2]: PydanticObjectId("64d6088586da7ecbfe53340f")
Out[2]: ObjectId('64d6088586da7ecbfe53340f')
In [3]: PydanticObjectId("123")
...
InvalidId: '123' is not a valid ObjectId, it must be a 12-byte input or a 24-character hex string |
Msgspec doesn't know how to handle this type. There is a |
|
Ah I was at the breaking commit, |
Yeah, we need to add those. We're lacking docs for a lot of serialisation intricacies in general. |
This seems to do the trick: app = Litestar(
route_handlers=[test],
type_encoders={PydanticObjectId: str},
type_decoders=[
(
lambda target_type: issubclass(target_type, PydanticObjectId),
lambda target_type, value: target_type.validate(value),
)
],
) Wondering if it would be possible to support automatically all Pydantic custom data types with |
Should be. We'd just need to add logic for those to the Pydantic plugin. |
Thanks, closing this. |
Description
I tried upgrading from v2.0.0beta2 to the latest main and found that using a
beanie.PydanticObjectId
as path parameter raises validation error. Using git bisect I traced it down to b32088f.URL to code causing the issue
No response
MCVE
Steps to reproduce
Right before b32088f (66700b7):
At b32088f:
Logs
No response
Litestar Version
b32088f
Platform
Funding
The text was updated successfully, but these errors were encountered: