Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

from_any_pb gives a useless error message when the type names don't match. #711

Description

@MarkDaoust

Environment details

  • google-api-core version: pip show google-api-core = 2.19.2

Steps to reproduce

Try to decode an Any with the wrong type path.

The error is like:

TypeError: Could not convert `Any` to `PredictLongRunningResponse` 

I had to go way down in the debugger to find that the actual problem was the different versions:

TypeError: Could not convert
Any[google.ai.generativelanguage.v1main.PredictLongRunningResponse] to
google.ai.generativelanguage.v1beta.PredictLongRunningResponse

Code example

In this Colab example, the API doesn't know what version the client library is calling with and returns an Any with a mismatched-version.

https://colab.research.google.com/drive/1m6KLCvp2l1oD32cnIsaBLN5ecmbFNncI?resourcekey=0-hivajkhDg2FA5Sec3pTu4w&usp=sharing

Stack trace

<ipython-input-112-5c7fa9bc2888>(3)<cell line: 3>()
1 import time
2 ----> 3 while not op.done():
4 time.sleep(5)
5 print('waiting...')
/usr/local/lib/python3.10/dist-packages/google/api_core/operation.py(174)done()
172 bool: True if the operation is complete, False otherwise.
173 """
--> 174 self._refresh_and_update(retry)
175 return self._operation.done
176 /usr/local/lib/python3.10/dist-packages/google/api_core/operation.py(163)_refresh_and_update()
161 if not self._operation.done:
162 self._operation = self._refresh(retry=retry) if retry else self._refresh()
--> 163 self._set_result_from_operation()
164 165 def done(self, retry=None):
/usr/local/lib/python3.10/dist-packages/google/api_core/operation.py(134)_set_result_from_operation()
132 133 if self._operation.HasField("response"):
--> 134 response = protobuf_helpers.from_any_pb(
135 self._result_type, self._operation.response
136 )
> /usr/local/lib/python3.10/dist-packages/google/api_core/protobuf_helpers.py(65)from_any_pb()
63 # Unpack the Any object and populate the protobuf message instance.
64 if not any_pb.Unpack(msg_pb):
---> 65 raise TypeError(
66 "Could not convert {} to {}".format(
67 any_pb.__class__.__name__, pb_type.__name__

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in 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