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

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

Open
MarkDaoust opened this issue Oct 1, 2024 · 1 comment · May be fixed by #712
Open

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

MarkDaoust opened this issue Oct 1, 2024 · 1 comment · May be fixed by #712
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@MarkDaoust
Copy link
Contributor

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__

@MarkDaoust MarkDaoust linked a pull request Oct 1, 2024 that will close this issue
4 tasks
@ohmayr
Copy link
Contributor

ohmayr commented Oct 4, 2024

@MarkDaoust Thanks for filing this issue and proposing a fix. We will take a look!

@ohmayr ohmayr added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants