Skip to content

Add support for Protobuf 7.34.0rc1 pre-release #558

@parthea

Description

@parthea

protobuf==7.34.0rc1 pre-release was published today but it's not supported because float_precision was removed from MessageToDict in this major version. float_precision can't be used in protobuf 7.x. Specifically the else code path below should be updated to remove float_precision (and potentially maintain backwards compatibility for folks that use it with protobuf 6.x):

if PROTOBUF_VERSION[0] in ("3", "4"):
return MessageToDict(
cls.pb(instance),
including_default_value_fields=print_fields,
preserving_proto_field_name=preserving_proto_field_name,
use_integers_for_enums=use_integers_for_enums,
float_precision=float_precision,
)
else:
# The `including_default_value_fields` argument was removed from protobuf 5.x
# and replaced with `always_print_fields_with_no_presence` which very similar but has
# handles optional fields consistently by not affecting them.
# The old flag accidentally had inconsistent behavior between proto2
# optional and proto3 optional fields.
return MessageToDict(
cls.pb(instance),
always_print_fields_with_no_presence=print_fields,
preserving_proto_field_name=preserving_proto_field_name,
use_integers_for_enums=use_integers_for_enums,
float_precision=float_precision,
)

See the following stack trace. Also see googleapis/google-cloud-python#15099 which is to deprecate float_precision

________________________ Test_SinksAPI.test_list_sinks _________________________

self = 

    def test_list_sinks(self):
        client = self.make_sinks_api()
    
        sink_msg = LogSink(
            name=self.SINK_NAME, destination=self.DESTINATION_URI, filter=FILTER
        )
        with mock.patch.object(
            type(client._gapic_api.transport.list_sinks), "__call__"
        ) as call:
            call.return_value = logging_v2.types.ListSinksResponse(sinks=[sink_msg])
    
            result = client.list_sinks(
                self.PARENT_PATH,
            )
    
>       sinks = list(result)
                ^^^^^^^^^^^^

tests/unit/test__gapic.py:239: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
google/cloud/logging_v2/_gapic.py:235: in sinks_pager
    yield Sink.from_api_repr(LogSink.to_dict(entry), client=self._client)
                             ^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = 
instance = name: "sink_name"
destination: "faux.googleapis.com/destination"
filter: "logName:syslog AND severity>=ERROR"


    def to_dict(
        cls,
        instance,
        *,
        use_integers_for_enums=True,
        preserving_proto_field_name=True,
        including_default_value_fields=None,
        float_precision=None,
        always_print_fields_with_no_presence=None,
    ) -> Dict[str, Any]:
        """Given a message instance, return its representation as a python dict.
    
        Args:
            instance: An instance of this message type, or something
                compatible (accepted by the type's constructor).
            use_integers_for_enums (Optional(bool)): An option that determines whether enum
                values should be represented by strings (False) or integers (True).
                Default is True.
            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)): 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.
                This value must match `always_print_fields_with_no_presence`,
                if both arguments are explicitly set.
            float_precision (Optional(int)): If set, use this to specify float field valid digits.
                Default is None.
            always_print_fields_with_no_presence (Optional(bool)): If True, fields without
                presence (implicit presence scalars, repeated fields, and map fields) will
                always be serialized. Any field that supports presence is not affected by
                this option (including singular message fields and oneof fields). This value
                must match `including_default_value_fields`, if both arguments are explicitly set.
    
        Returns:
            dict: A representation of the protocol buffer using pythonic data structures.
                  Messages and map fields are represented as dicts,
                  repeated fields are represented as lists.
        """
    
        print_fields = cls._normalize_print_fields_without_presence(
            always_print_fields_with_no_presence, including_default_value_fields
        )
    
        if PROTOBUF_VERSION[0] in ("3", "4"):
            return MessageToDict(
                cls.pb(instance),
                including_default_value_fields=print_fields,
                preserving_proto_field_name=preserving_proto_field_name,
                use_integers_for_enums=use_integers_for_enums,
                float_precision=float_precision,
            )
        else:
            # The `including_default_value_fields` argument was removed from protobuf 5.x
            # and replaced with `always_print_fields_with_no_presence` which very similar but has
            # handles optional fields consistently by not affecting them.
            # The old flag accidentally had inconsistent behavior between proto2
            # optional and proto3 optional fields.
>           return MessageToDict(
                cls.pb(instance),
                always_print_fields_with_no_presence=print_fields,
                preserving_proto_field_name=preserving_proto_field_name,
                use_integers_for_enums=use_integers_for_enums,
                float_precision=float_precision,
            )
E           TypeError: MessageToDict() got an unexpected keyword argument 'float_precision'

Metadata

Metadata

Assignees

Labels

priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions