-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[Feature] Include _data
in Event
serialization by default.
#16841
[Feature] Include _data
in Event
serialization by default.
#16841
Conversation
@@ -68,7 +74,8 @@ def __init__(self, **params: Any): | |||
super().__init__(**fields) | |||
for private_attr, value in private_attrs.items(): | |||
super().__setattr__(private_attr, value) | |||
self._data = data | |||
if data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: the super().__init__(...)
call sets the PrivateAttr _data
since we defined it's default_factory
.
8f7fde9
to
45af7da
Compare
deseriazlied_ev, | ||
) | ||
assert ev.param == deseriazlied_ev.param | ||
assert ev._data == deseriazlied_ev._data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This last assertion fails without the custom additions to Event.model_dump() in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the thorough explanation!
Description
With our
Event
abstraction, we can store data inFields
,PrivateAttr
as well as_data
. Specifically, a user can subclassEvent
to define their own customFields
, andPrivateAttr
. And,_data
acts like an underlyingdict
as well:Field
orPrivateAttr
of theEvent
gets added to_data
._data
via a dictionary-like interface as well as via dot notationThis is kind of is against Pydantic
BaseModel
convention in thatPrivateAttr
's start with an underscore "_" and are known to not be included in the model serialization. So, should we include_data
by defaul in model serialization?Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.