-
Notifications
You must be signed in to change notification settings - Fork 229
to_dict() fails to write boolean fields without default when value is False #95
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
Comments
I assume you have tried If so, could you clarify why this option does not solve your problem? Background
If you are hinting at a version of |
I've looked at how the Dart implementation handles this: On a client-side generated object, message Position {
int32 x = 1;
int32 y = 2;
} var p = Position();
print (p.writeToBuffer()); // prints []
p = Position()..x=0..y=0;
print (p.writeToBuffer()); // prints [8, 0, 16, 0] Internally, So we could probably do the same, if it works for dart 😃 |
Thanks for your answer !
This is important in my opinion as having a field being false or 0 is not the same as not having data for it. |
When you have a message with a boolean value as follows:
then an object like
fails to write the
is_rna_available
field when it is False when callingpatient.to_dict()
, this does not happen when the value is True.The issue seems to be in line 824 of file
betterproto/__init__py
where it runs the following comparisonelif v != self._get_field_default(field, meta) or include_default_values:
. It should be something like 'elif v != None or include_default_values', otherwise when you set a field to the same value as the default value and do not setinclude_default values
then it is not written. This may be also the case for other types.The text was updated successfully, but these errors were encountered: