Open dhendry opened 4 years ago
I hacked together a proposed fix for this in https://github.com/danielgtaylor/python-betterproto/pull/110. I'm also really impressed with this project!
See also:
Thank you for your great write-up! This makes a clear case to include the default values in the output.
I'll respond further in your PR 😄
As for your other suggestions, they are all valuable ideas. As it will be hard to track them being inside this issue, if you like, please create a proposal for those so we can categorize / prioritize them, and discuss them separately.
I'm not sure whether this is the correct place to comment, but I've noticed that the default values are also not serialized when calling bytes() on a dataclass for a oneoff.
I have a message with a oneoff field. One of the options of the oneoff is a submessage with two required fields, an enum field and a uint32 field. when calling bytes(message) with the default value (which is 0) on the uint32 field, it is not added to the binary data.
When I do the same using the default python protobuff implementation this field is added to the binary data.
enum Enum {
a = 1;
b = 2;
};
enum OtherEnum {
c = 3;
d = 4;
};
message First{
required OtherEnum enum_name = 1;
required uint32 uint32_name = 2;
};
message Second{
required uint32 offset = 1;
required bytes data = 2;
}
message MyMessage{
required Enum myEnum = 1;
oneof params {
First first = 2;
Second second = 3;
}
};
So in the case of MyMessage(myEnum=Enum.a, first=First(enum_name=OtherEnum.d, uint32_name =0)
when bytes
is called, the uint32_name field is not present in the binary data even though it is required.
If this belongs in a seperate issue please let me know.
Consider this protobuf message:
Using the official protobuf codegen and library (libprotoc 3.12.3):
Using betterproto (1.2.5)
This obviously leads to the following inconsistency:
Misc
Optional
? (ie:bool_value: Optional[bool]
) since only one is expected to be set? Personally I would prefer this but I can understand if its getting too far away from the idea of "there are no nulls in proto3"..to_json()
is missing thecasing
arg (andinclude_default_values
) from.to_dict()
Casing.SNAKE
for all.to_json()
operations automatically. Perhaps something like a default option you could specify on a per message basis?Great work on this project! Keep it up!