You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Evaluate moving to pydantic model instead of dataclass for Event
What about avro, or protobuf?
In [9]: importdatetimeIn [10]: fromdataclassesimportdataclass, asdictIn [11]: @dataclass
...: classEvent:
...: data: strIn [12]: bus.register_event("airbase.event_store.event", Event)
In [13]: event=Event(data=datetime.datetime.now())
In [14]: bus.send(event)
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
One side-effect of using dataclass in the eventbus is dataclass values aren't type validated during creation. As result the failure happens at the lowest layer while converting to JSON. This becomes painful to debug when there one of the field is nested dictionary and can't be converted to JSON by json.dumps.
If we use pydantic the type check will kick in during object creation and can prevent the error happening at lower level.
The text was updated successfully, but these errors were encountered:
sidmitra
changed the title
Evaluate moving to pydantic model instead of dataclass for Event
Add runtime type validation for Event class
Feb 3, 2023
The text was updated successfully, but these errors were encountered: