From 10e76dae40571a4dc57fef01e40c8a12ca32282a Mon Sep 17 00:00:00 2001 From: Matthew Tang Date: Thu, 15 Oct 2026 13:21:05 -0700 Subject: [PATCH] chore: Add protobuf 7.x support Fixes #7132 PiperOrigin-RevId: 1000347632 --- .../cloud/aiplatform/_streaming_prediction.py | 4 +-- setup.py | 2 +- testing/constraints-3.14.txt | 4 +-- testing/constraints-3.8.txt | 16 ---------- testing/constraints-3.9.txt | 15 --------- testing/constraints-adk.txt | 1 + tests/unit/aiplatform/test_initializer.py | 31 +++++++------------ 7 files changed, 17 insertions(+), 56 deletions(-) delete mode 100644 testing/constraints-3.8.txt delete mode 100644 testing/constraints-3.9.txt diff --git a/google/cloud/aiplatform/_streaming_prediction.py b/google/cloud/aiplatform/_streaming_prediction.py index 9225519c26..a48ad77171 100644 --- a/google/cloud/aiplatform/_streaming_prediction.py +++ b/google/cloud/aiplatform/_streaming_prediction.py @@ -38,12 +38,12 @@ def value_to_tensor(value: Any) -> aiplatform_types.Tensor: """ if value is None: return aiplatform_types.Tensor() + elif isinstance(value, bool): + return aiplatform_types.Tensor(bool_val=[value]) elif isinstance(value, int): return aiplatform_types.Tensor(int_val=[value]) elif isinstance(value, float): return aiplatform_types.Tensor(float_val=[value]) - elif isinstance(value, bool): - return aiplatform_types.Tensor(bool_val=[value]) elif isinstance(value, str): return aiplatform_types.Tensor(string_val=[value]) elif isinstance(value, bytes): diff --git a/setup.py b/setup.py index 037f1a0d14..7a78fe99fd 100644 --- a/setup.py +++ b/setup.py @@ -322,7 +322,7 @@ "google-auth >= 2.47.0, <3.0.0", "certifi >= 2023.7.22", "proto-plus >= 1.22.3, <2.0.0", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf>=3.20.2,<8.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", "packaging >= 14.3", "google-cloud-storage >= 1.32.0, < 4.0.0; python_version<'3.13'", "google-cloud-storage >= 3.10.0, < 4.0.0; python_version>='3.13'", diff --git a/testing/constraints-3.14.txt b/testing/constraints-3.14.txt index 66f1c92acc..b06a8184d3 100644 --- a/testing/constraints-3.14.txt +++ b/testing/constraints-3.14.txt @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # This constraints file is required for unit tests. # List all library dependencies and extras in this file. -google-api-core==2.27.0 google-auth==2.49.0 proto-plus mock==4.0.2 @@ -13,4 +12,5 @@ ipython==8.22.2 # Pinned to unbreak TypeAliasType import error google-adk==0.0.2 google-genai>=1.10.0 google-vizier==0.1.21 -pyarrow>=22.0.0 \ No newline at end of file +pyarrow>=22.0.0 +protobuf>=7 \ No newline at end of file diff --git a/testing/constraints-3.8.txt b/testing/constraints-3.8.txt deleted file mode 100644 index cbd2bf5690..0000000000 --- a/testing/constraints-3.8.txt +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List *all* library dependencies and extras in this file. -google-api-core==2.17.1 # Increased for gapic owlbot presubmit tests -google-auth==2.14.1 # Tests google-auth without rest async support -proto-plus==1.22.3 -protobuf -mock==4.0.2 -google-cloud-storage==3.0.0 # Updated to v3.x, backward compatible with v2.x via wrapper -packaging==24.1 # Increased to unbreak canonicalize_version error (b/377774673) -grpcio-testing==1.34.0 -pytest-xdist==3.3.1 # Pinned to unbreak unit tests -ray==2.4.0 # Pinned until 2.9.3 is verified for Ray tests -google-vizier==0.1.21 -google-adk==0.0.2 diff --git a/testing/constraints-3.9.txt b/testing/constraints-3.9.txt deleted file mode 100644 index 63f2d6d147..0000000000 --- a/testing/constraints-3.9.txt +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core==2.21.0 # Tests google-api-core with rest async support -google-auth==2.47.0 # Tests google-auth with rest async support -proto-plus==1.22.3 -protobuf -mock==4.0.2 -google-cloud-storage==3.0.0 # Updated to v3.x, backward compatible with v2.x via wrapper -packaging==24.1 # Increased to unbreak canonicalize_version error (b/377774673) -grpcio-testing==1.34.0 -pytest-xdist==3.3.1 # Pinned to unbreak unit tests -ray==2.4.0 # Pinned until 2.9.3 is verified for Ray tests -google-vizier==0.1.21 -google-adk==0.0.2 \ No newline at end of file diff --git a/testing/constraints-adk.txt b/testing/constraints-adk.txt index e69de29bb2..cf35a999af 100644 --- a/testing/constraints-adk.txt +++ b/testing/constraints-adk.txt @@ -0,0 +1 @@ +protobuf<5.0.0 diff --git a/tests/unit/aiplatform/test_initializer.py b/tests/unit/aiplatform/test_initializer.py index fe12dbdb99..d925bf7f4d 100644 --- a/tests/unit/aiplatform/test_initializer.py +++ b/tests/unit/aiplatform/test_initializer.py @@ -385,12 +385,9 @@ def test_create_client_user_agent(self): client_class=utils.ModelClientWithOverride ) - for wrapped_method in client._transport._wrapped_methods.values(): - # wrapped_method._metadata looks like: - # [('x-goog-api-client', 'model-builder/0.3.1 gl-python/3.7.6 grpc/1.30.0 gax/1.22.2 gapic/0.3.1')] - user_agent = wrapped_method._metadata[0][1] - assert "model-builder/" in user_agent - assert "google.cloud.aiplatform" in user_agent + user_agent = client._client_info.to_user_agent() + assert "model-builder/" in user_agent + assert "google.cloud.aiplatform" in user_agent def test_create_client_user_agent_top_level_method(self): initializer.global_config.init(project=_TEST_PROJECT, location=_TEST_LOCATION) @@ -404,14 +401,11 @@ def __init__(self): client_class=utils.ModelClientWithOverride ) - for wrapped_method in SomeClass()._client._transport._wrapped_methods.values(): - # wrapped_method._metadata looks like: - # [('x-goog-api-client', 'model-builder/0.3.1 gl-python/3.7.6 grpc/1.30.0 gax/1.22.2 gapic/0.3.1')] - user_agent = wrapped_method._metadata[0][1] - assert ( - f"+{initializer._TOP_GOOGLE_CONSTRUCTOR_METHOD_TAG}+vertexai.SomeClass.__init__" - in user_agent - ) + user_agent = SomeClass()._client._client_info.to_user_agent() + assert ( + f"+{initializer._TOP_GOOGLE_CONSTRUCTOR_METHOD_TAG}+vertexai.SomeClass.__init__" + in user_agent + ) def test_create_client_appended_user_agent(self): appended_user_agent = ["fake_user_agent", "another_fake_user_agent"] @@ -421,12 +415,9 @@ def test_create_client_appended_user_agent(self): appended_user_agent=appended_user_agent, ) - for wrapped_method in client._transport._wrapped_methods.values(): - # wrapped_method._metadata looks like: - # [('x-goog-api-client', 'model-builder/0.3.1 gl-python/3.7.6 grpc/1.30.0 gax/1.22.2 gapic/0.3.1')] - user_agent = wrapped_method._metadata[0][1] - assert " " + appended_user_agent[0] in user_agent - assert " " + appended_user_agent[1] in user_agent + user_agent = client._client_info.to_user_agent() + assert " " + appended_user_agent[0] in user_agent + assert " " + appended_user_agent[1] in user_agent def test_set_api_endpoint(self): initializer.global_config.init(