Serialization of pydantic models on publish #74
Closed
bodograumann
started this conversation in
Ideas
Replies: 2 comments 3 replies
-
It's a funny, but it is the most suitable way to use if isinstance(m, (Dict, Sequence)):
return obj.json()[12:-1].encode(), ContentTypes.json.value |
Beta Was this translation helpful? Give feedback.
0 replies
-
So, I got an elegant solution to serialize publishing messages. With handlers should be any problems cuz they are serializing at FastDepends by pydantic model. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to send a pydantic object with broker.publish and it is unable to serialize datetime fields:
I think this part of the code is relevant:
https://github.com/Lancetnik/Propan/blob/main/propan/brokers/_model/schemas.py#L199
When I encode it myself beforehand, datetime fields are handled automatically by pydantic, e.g.
broker.publish(pydantic_object.json(), content_type="application/json", …)
.Can you also use the pydantic json-serialization logic automatically here?
PS: A similar issue could exist when returning a pydantic object from a handler method on the server side.
Beta Was this translation helpful? Give feedback.
All reactions