You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "robertwb (via GitHub)" <gi...@apache.org> on 2023/02/21 23:24:23 UTC

[GitHub] [beam] robertwb commented on a diff in pull request #24599: Update Python SDK build dependencies

robertwb commented on code in PR #24599:
URL: https://github.com/apache/beam/pull/24599#discussion_r1113671034


##########
sdks/python/apache_beam/io/gcp/datastore/v1new/util.py:
##########
@@ -137,3 +137,22 @@ def report_latency(self, now, latency_ms, num_mutations):
       num_mutations: int, number of mutations contained in the RPC.
     """
     self._commit_time_per_entity_ms.add(now, latency_ms / num_mutations)
+
+
+def extract_byte_size(proto_message):
+  """
+    Gets the byte size from a google.protobuf or proto-plus message
+
+    google-cloud-datastore moved from using protobuf to using
+    proto-plus messages.
+    protobuf object has attribute ByteSize() but proto.Message() objects
+    don't. Workaround:
+    https://github.com/googleapis/proto-plus-python/issues/163
+    """
+  if hasattr(proto_message, "ByteSize"):
+    # google.protobuf message
+    return proto_message.ByteSize()
+  if hasattr(type(proto_message), "pb"):
+    # proto-plus message
+    return type(proto_message).pb(proto_message).ByteSize()
+  return None

Review Comment:
   Throw an exception here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org