-
Notifications
You must be signed in to change notification settings - Fork 218
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
Set serialized_on_wire when message contains only lists #81
Set serialized_on_wire when message contains only lists #81
Conversation
This fixes a bug where serialized_on_wire was not set when a message contained only repeated values (eg in a list or map). The fix here is to just set it to true in the `parse` method as soon as we receive any valid data. This also adds a test to expose the behavior.
Let me know if there's another approach here that you think would be better! Also, I wasn't sure if this is the right place to put these tests (I was also looking at the |
This is similar to the fix at danielgtaylor#81, but that doesn't merge into our branch because our branch is too old. So this just pulls in the relevant fix part.
This is similar to the fix at danielgtaylor#81, but that doesn't merge into our branch because our branch is too old. So this just pulls in the relevant fix part.
Thank you for the bugfix @FuegoFro ! Test location is fine I think, we haven't completely organized our tests yet anyway, although there are also tests for python-betterproto/betterproto/tests/test_features.py Lines 6 to 33 in eec24e4
I quickly added a test for a message without any fields except @dataclass
class MessageWithRepeatedField(betterproto.Message):
repeated: List[str] = betterproto.string_field(1)
repeated = MessageWithRepeatedField()
assert betterproto.serialized_on_wire(repeated) == False
repeated.repeated = ["foo", "bar", "baz"]
assert betterproto.serialized_on_wire(repeated) == True So is the bug only happening when when RPC-services return data? And if so, how come it only occurs for repeated fields? Because the fix seems not specific to repeated fields, but sets the flag for all decoded messages... |
Thanks for the quick reply! The code in question is here: python-betterproto/betterproto/__init__.py Lines 777 to 783 in eec24e4
Since we set I considered just adding I think |
I see! Thank you for your clear explanation, and updates! In that case, it seems that moving it to the top makes more sense, then anything that was parsed will be considered as arriving 'from the wire'. So also cases with If you'd like to include that improvement in this PR (and perhaps including an updated test) I will wait for that. Otherwise I'll create an issue for the remaining cases. Thanks for your work! 🥳 And clever to use |
I think with the latest changes this should be good to go, but let me know if there's anything else you'd like to see changed 😀 |
I see, thanks so much for your quick changes~ About the |
Merging this in absence of further feedback. Thank you for your contribution! 🥇 |
This fixes a bug where serialized_on_wire was not set when a message contained only repeated values (eg in a list or map). The fix here is to just set it to true in the
parse
method as soon as we receive any valid data. This also adds a test to expose the behavior.