Skip to content
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

Nested message with repeated field not in to_json when mutated after initialization #543

Open
3 tasks done
dallagi opened this issue Nov 14, 2023 · 0 comments
Open
3 tasks done
Labels
bug Something isn't working investigation needed

Comments

@dallagi
Copy link

dallagi commented Nov 14, 2023

Summary

Possibly related to #199

Given a message with a nested message field containing a repeated field, if the field is mutated (eg. via list.append) after initialization, to_dict will not include it.

Reproduction Steps

Given a proto schema like this

syntax = "proto3";

message RootMessage {
  NestedMessage nested = 1;
}

message NestedMessage {
  repeated string content = 1;
}

Running the following script

message = RootMessage()

message.nested.content.append("test-content")

print("Including default values: True")
pprint(message.to_dict(include_default_values=True))

print("Including default values: False")
pprint(message.to_dict(include_default_values=False))

will result in:

Including default values: True
{'nested': {'content': ['test-content']}}

Including default values: False
{}

Expected Results

I would expect the content field of the nested message to appear in the returned dict also when include_default_values is set to False, as its content was mutated and it's no longer the default value.

Actual Results

to_dict returns an empty dict

System Information

libprotoc 3.21.6
Python 3.10.13
Name: betterproto
Version: 2.0.0b6
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: [email protected]
License: MIT
Location: /home/marco/.local/share/rtx/installs/python/3.10.13/lib/python3.10/site-packages
Requires: grpclib, python-dateutil
Required-by: 

Checklist

  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have verified this issue occurs on the latest prelease of betterproto which can be installed using pip install -U --pre betterproto, if possible.
@dallagi dallagi added bug Something isn't working investigation needed labels Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigation needed
Projects
None yet
Development

No branches or pull requests

1 participant