-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
msgspec: support omit_defaults
option
#2205
Comments
Looking at the default template, this may already be possible via the Attempting to infer the behaviour from code inspection:
Assuming I've understood the behaviour, this feature already exists by way of passing |
I realised I was still missing something, as after attempting to set extra_template_data = defaultdict(
lambda: {
"base_class_kwargs": {
"omit_defaults": True,
"check_execution": 1/0
}
}
) (I also checked the version, and 0.26.3 is new enough that the class kwarg support should be in place for msgspec) I then switched over to the following and it worked: extra_template_data = defaultdict(
dict,
{
"#all#": {
"base_class_kwargs": {
"omit_defaults": True,
}
}
}
) This suggests to me that something somewhere is checking |
After resolving the |
Is your feature request related to a problem? Please describe.
When #1551 added
msgspec
support, it was noted that theomit_defaults
option wasn't supported.I'm currently choosing between Pydantic v2 and msgspec as my wire validation format, but need to be able to omit optional fields (the server complains if optional fields are populated on message types they don't apply to).
In Pydantic, whether to omit optional fields is set when dumping the model as a dict, in MsgSpec it needs to be set on the model classes themselves.
Describe the solution you'd like
An
--omit-defaults
option to set the option in the generated MsgSpec code.Describe alternatives you've considered
Adding a custom template to include the option in the generated class entries.
The text was updated successfully, but these errors were encountered: