You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by sh...@apache.org on 2026/04/24 18:36:57 UTC
(airflow) branch main updated: Fix GenAIGenerativeModelHook ignoring Airflow connection credentials (#65731)
This is an automated email from the ASF dual-hosted git repository.
shahar1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 86511d69795 Fix GenAIGenerativeModelHook ignoring Airflow connection credentials (#65731)
86511d69795 is described below
commit 86511d697959d5729670068d35505bbaf8f1c566
Author: Sadha Chilukoori <sr...@gmail.com>
AuthorDate: Fri Apr 24 11:36:49 2026 -0700
Fix GenAIGenerativeModelHook ignoring Airflow connection credentials (#65731)
---
.../src/airflow/providers/google/cloud/hooks/gen_ai.py | 1 +
.../google/tests/unit/google/cloud/hooks/test_gen_ai.py | 15 +++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/providers/google/src/airflow/providers/google/cloud/hooks/gen_ai.py b/providers/google/src/airflow/providers/google/cloud/hooks/gen_ai.py
index c71f3147382..c363c3efbdf 100644
--- a/providers/google/src/airflow/providers/google/cloud/hooks/gen_ai.py
+++ b/providers/google/src/airflow/providers/google/cloud/hooks/gen_ai.py
@@ -73,6 +73,7 @@ class GenAIGenerativeModelHook(GoogleBaseHook):
vertexai=True,
project=project_id,
location=location,
+ credentials=self.get_credentials(),
)
@GoogleBaseHook.fallback_to_default_project_id
diff --git a/providers/google/tests/unit/google/cloud/hooks/test_gen_ai.py b/providers/google/tests/unit/google/cloud/hooks/test_gen_ai.py
index e0ac0fb327b..4bc691ad52b 100644
--- a/providers/google/tests/unit/google/cloud/hooks/test_gen_ai.py
+++ b/providers/google/tests/unit/google/cloud/hooks/test_gen_ai.py
@@ -134,6 +134,21 @@ class TestGenAIGenerativeModelHookWithDefaultProjectId:
self.hook = GenAIGenerativeModelHook(gcp_conn_id=TEST_GCP_CONN_ID)
self.hook.get_credentials = self.dummy_get_credentials
+ @mock.patch("google.genai.Client")
+ def test_get_genai_client_passes_connection_credentials(self, mock_client) -> None:
+ """get_genai_client must pass Airflow connection credentials to genai.Client, not fall back to ADC."""
+ mock_credentials = mock.Mock()
+ self.hook.get_credentials = mock.Mock(return_value=mock_credentials)
+
+ self.hook.get_genai_client(project_id=GCP_PROJECT, location=GCP_LOCATION)
+
+ mock_client.assert_called_once_with(
+ vertexai=True,
+ project=GCP_PROJECT,
+ location=GCP_LOCATION,
+ credentials=mock_credentials,
+ )
+
@mock.patch(GENERATIVE_MODEL_STRING.format("GenAIGenerativeModelHook.get_genai_client"))
def test_text_embedding_model_get_embeddings(self, mock_get_client) -> None:
client_mock = mock_get_client.return_value