googleapis / python-aiplatform

A Python SDK for Vertex AI, a fully managed, end-to-end platform for data science and machine learning.
Apache License 2.0
615 stars 330 forks source link

`Part.text` raises `ValueError` incorrectly #3411

Closed ccurro closed 6 months ago

ccurro commented 6 months ago

https://github.com/googleapis/python-aiplatform/blob/a9010aad6eaaa8cde335f5f8b25591a48a43b085/vertexai/generative_models/_generative_models.py#L1604-L1609

In this snippet, the SDK raises a ValueError when there is no accessible .text attribute. To be compatible with Python's hasattr this should raise an AttributeError.

Additionally, the Python docs make it quite clear this is not an intended use for ValueError:

exception ValueError

Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError.

Emphasis on receives, which does not describe a scenario in which a user may access a .text part but find it non-existent.

cc: @yeesian

Environment details

N/A

Steps to reproduce

N/A

Code example

N/A

Stack trace

N/A

jaycee-li commented 6 months ago

Fixed in https://github.com/googleapis/python-aiplatform/commit/b91edf52e2b993c3301a419ad89b473c31c60cc3