Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d5ed37

Browse files
fix: ImproveAny decode error (#712)
* Improve Any decoding-error.Was:TypeError: Could not convert Any to PredictLongRunningResponseNow:TypeError: Could not convert Any[google.ai.generativelanguage.v1main.PredictLongRunningResponse] to google.ai.generativelanguage.v1beta.PredictLongRunningResponse* update test* update error message* address review feedback---------Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent4dbb405 commit0d5ed37

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

‎google/api_core/protobuf_helpers.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def from_any_pb(pb_type, any_pb):
6363
# Unpack the Any object and populate the protobuf message instance.
6464
ifnotany_pb.Unpack(msg_pb):
6565
raiseTypeError(
66-
"Could not convert {} to {}".format(
67-
any_pb.__class__.__name__,pb_type.__name__
68-
)
66+
f"Could not convert `{any_pb.TypeName()}` with underlying type `google.protobuf.any_pb2.Any` to `{msg_pb.DESCRIPTOR.full_name}`"
6967
)
7068

7169
# Done; return the message.

‎tests/unit/test_protobuf_helpers.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
importpytest
16+
importre
1617

1718
fromgoogle.apiimporthttp_pb2
1819
fromgoogle.api_coreimportprotobuf_helpers
@@ -65,7 +66,12 @@ def test_from_any_pb_failure():
6566
in_message=any_pb2.Any()
6667
in_message.Pack(date_pb2.Date(year=1990))
6768

68-
withpytest.raises(TypeError):
69+
withpytest.raises(
70+
TypeError,
71+
match=re.escape(
72+
"Could not convert `google.type.Date` with underlying type `google.protobuf.any_pb2.Any` to `google.type.TimeOfDay`"
73+
),
74+
):
6975
protobuf_helpers.from_any_pb(timeofday_pb2.TimeOfDay,in_message)
7076

7177

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp