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
fix: Add compatibility with protobuf==5.x #433
base: main
Are you sure you want to change the base?
Conversation
8ea8426
to
39e4d33
Compare
39e4d33
to
62b37ee
Compare
259b2a4
to
19c487f
Compare
proto/message.py
Outdated
including_default_value_fields (Optional(bool)): Deprecated. Use argument | ||
`always_print_fields_with_no_presence` instead. An option that | ||
determines whether the default field values should be included in the results. | ||
Default is True. If `always_print_fields_with_no_presence` is set to False, this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these fields say that they don't take effect if the other is False. This is confusing enough that it's not obvious what the right semantics are and whether they make sense.
I recommend setting the default value for both fields in the arg list above to be None
, and then using them thus:
if ((always_print_fields_with_no_presence is not None) and
(including_default_value_fields is not None) and
(always_print_fields_with_no_presence != including_default_value_fields):
raise ValueError("new and deprecated parameters are inconsistent")
print_field = (always_print_fields_with_no_presence if always_print_fields_with_no_presence is not None
else (including_default_value_fields if including_default_value_fields is not None
else True)
and simplifying the comments for both parameters to say that any value explicitly provided for one must be consistent with the any value explicitly provided for the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0e65d18
proto/message.py
Outdated
return MessageToJson( | ||
cls.pb(instance), | ||
use_integers_for_enums=use_integers_for_enums, | ||
including_default_value_fields=including_default_value_fields, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're deprecating this field on thisA PI surface, we should have the same deprecation logic on the RHS here as in the else
branch (and I suggest the print_field
variable I defined in my other comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0e65d18
@@ -448,24 +483,49 @@ def to_dict( | |||
preserving_proto_field_name (Optional(bool)): An option that | |||
determines whether field name representations preserve | |||
proto case (snake_case) or use lowerCamelCase. Default is True. | |||
including_default_value_fields (Optional(bool)): An option that | |||
including_default_value_fields (Optional(bool)): Deprecated. Use argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as in to_json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0e65d18
The pre-release failure in https://github.com/googleapis/proto-plus-python/actions/runs/8758049270/job/24037997447 is captured in #444 |
…Python object in tests
327fb52
to
09b9bc4
Compare
BEGIN_COMMIT_OVERRIDE
feat: Add
always_print_fields_with_no_presence
fields toto_json
andto_dict
docs: Deprecate field
including_default_value_fields
into_json
andto_dict
fix: Add compatibility with protobuf==5.x
fix: AttributeError module 'google._upb._message' has no attribute 'MessageMapContainer'
ci: Add support for pre-release sessions
ci: Add python 3.13 to testing matrix
ci: Resolve
RecursionError: maximum recursion depth exceeded while calling a Python object
when running testsEND_COMMIT_OVERRIDE
Fixes #425
Fixes #427
Fixes #431
Fixes #445
For compatibility with https://pypi.org/project/protobuf/5.26.0rc2/
See protocolbuffers/protobuf@2699579