-
Notifications
You must be signed in to change notification settings - Fork 229
to_dict modifies the underlying message #151
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
Thanks for reporting this. If you could add a failing test case following the existing pattern then that would be a huge help. |
Test as diff from the current master (17.10.2020, ID: bf9412e) diff --git a/tests/test_inputs.py b/tests/test_inputs.py
index f09ee79..737d7c7 100644
--- a/tests/test_inputs.py
+++ b/tests/test_inputs.py
@@ -165,3 +165,10 @@ def test_binary_compatibility(repeat, test_data: TestData) -> None:
assert (
plugin_instance_from_json.to_dict() == plugin_instance_from_binary.to_dict()
)
+
+@pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True)
+def test_to_dict(repeat, test_data: TestData) -> None:
+ plugin_module, reference_module, json_data = test_data
+ message = plugin_module.Test().from_json(json_data)
+ message.to_dict()
+ assert message == plugin_module.Test().from_json(json_data) Proto and message for the test (for me this bug happens only when enum is used as a map value) syntax = "proto3";
message Test {
map<string, Nested> items = 1;
}
enum Nested {
a = 0;
b = 1;
} {
"items": {
"foo": {
"count": 1
},
"bar": {
"count": 2
}
}
} Result
|
Also I've spotted that when you call |
Can confirm this occurs for any map which has a Message as a value. I think there's quite a simple fix, just need a slight modification to lines 1052-1058 of init.py, specifically line 1055.
Proposed fix
|
Can you test and PR this? |
* [fix] to_dict modifies the underlying message (#151) * add test for mapmessage * fix for to_dict * formatting * Apply suggestions from code review Co-authored-by: Arun Babu Neelicattu <[email protected]> * change to_json to to_dict Co-authored-by: Arun Babu Neelicattu <[email protected]>
Hi,
It seems that the
to_dict
method modifies the nested message.In short, here's the code and the output (version from master, pulled 24-09-2020)
Also, if you'll change
ONE
toZERO
, it won't print anything, asZERO
is a default value (even though it was set manually)The text was updated successfully, but these errors were encountered: