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

fix: Add compatibility with protobuf==5.x #433

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

parthea
Copy link
Contributor

@parthea parthea commented Feb 13, 2024

BEGIN_COMMIT_OVERRIDE
feat: Add always_print_fields_with_no_presence fields to to_json and to_dict
docs: Deprecate field including_default_value_fields in to_json and to_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 tests
END_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

@parthea parthea force-pushed the add-protobuf-5-compatibility branch 10 times, most recently from 8ea8426 to 39e4d33 Compare February 13, 2024 23:56
@parthea parthea changed the title ci: add support for pre-release sessions fix: compatibility with protobuf==5.26.0rc2 Feb 13, 2024
@parthea parthea changed the title fix: compatibility with protobuf==5.26.0rc2 fix: Fix compatibility with protobuf==5.26.0rc2 Feb 14, 2024
@parthea parthea force-pushed the add-protobuf-5-compatibility branch 2 times, most recently from 259b2a4 to 19c487f Compare February 14, 2024 15:10
@parthea parthea marked this pull request as ready for review February 14, 2024 15:11
@parthea parthea requested a review from a team as a code owner February 14, 2024 15:11
@parthea parthea added the owlbot:run Add this label to trigger the Owlbot post processor. label Feb 14, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Feb 14, 2024
@parthea parthea marked this pull request as draft February 20, 2024 19:16
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
Copy link
Contributor

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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).

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0e65d18

@parthea parthea changed the title fix: Fix compatibility with protobuf==5.26.0rc2 fix: Fix compatibility with protobuf==5.x Apr 19, 2024
@parthea
Copy link
Contributor Author

parthea commented Apr 19, 2024

@parthea parthea changed the title fix: Fix compatibility with protobuf==5.x fix!: Add compatibility with protobuf==5.x Apr 19, 2024
@parthea parthea added the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 25, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 25, 2024
@parthea parthea force-pushed the add-protobuf-5-compatibility branch from 327fb52 to 09b9bc4 Compare April 25, 2024 17:57
@parthea parthea added the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 25, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants