Skip to content

feat: fix dump one of fields #652

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/betterproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,9 @@ def dump(self, stream: "SupportsWrite[bytes]", delimit: bool = False) -> None:
field_name=field_name, meta=meta
)

if value == self._get_field_default(field_name) and not (
if not (
selected_in_group or serialize_empty or include_default_value_for_oneof
):
) and value == self._get_field_default(field_name):
# Default (zero) values are not serialized. Two exceptions are
# if this is the selected oneof item or if we know we have to
# serialize an empty message (i.e. zero value was explicitly
Expand Down Expand Up @@ -1074,9 +1074,9 @@ def __len__(self) -> int:
field_name=field_name, meta=meta
)

if value == self._get_field_default(field_name) and not (
if not (
selected_in_group or serialize_empty or include_default_value_for_oneof
):
) and value == self._get_field_default(field_name):
# Default (zero) values are not serialized. Two exceptions are
# if this is the selected oneof item or if we know we have to
# serialize an empty message (i.e. zero value was explicitly
Expand Down
Loading