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 161cff0d95e Normalize empty project id in credential config file 
branch (#73886)
161cff0d95e is described below

commit 161cff0d95e0c77e87d3a1db93e112ad8cbb5fee
Author: wiasliaw <[email protected]>
AuthorDate: Sat Oct 31 22:35:04 2026 +0800

    Normalize empty project id in credential config file branch (#73886)
    
    google-auth's load_credentials_from_file returns `str | None` for the
    project id, but _get_credentials_using_credential_config_file is
    annotated `-> tuple[Credentials, str]` and could hand `None` back to
    callers. The ADC branch (#61654) and the IdP branch (#72799) already
    normalize a missing project id to an empty string so the consumer
    decides how to handle it; this makes the third and last branch
    consistent with them, as suggested in the review of #72799.
---
 .../providers/google/cloud/utils/credentials_provider.py    |  2 ++
 .../unit/google/cloud/utils/test_credentials_provider.py    | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git 
a/providers/google/src/airflow/providers/google/cloud/utils/credentials_provider.py
 
b/providers/google/src/airflow/providers/google/cloud/utils/credentials_provider.py
index 19a23f0d4b3..5070cdc9a70 100644
--- 
a/providers/google/src/airflow/providers/google/cloud/utils/credentials_provider.py
+++ 
b/providers/google/src/airflow/providers/google/cloud/utils/credentials_provider.py
@@ -385,6 +385,8 @@ class _CredentialProvider(LoggingMixin):
                     temp_credentials_fd.name, scopes=self.scopes
                 )
 
+        if not project_id:
+            project_id = ""
         return credentials, project_id
 
     def _get_credentials_using_credential_config_file_and_token_supplier(self):
diff --git 
a/providers/google/tests/unit/google/cloud/utils/test_credentials_provider.py 
b/providers/google/tests/unit/google/cloud/utils/test_credentials_provider.py
index fb67303619f..2ba139faf78 100644
--- 
a/providers/google/tests/unit/google/cloud/utils/test_credentials_provider.py
+++ 
b/providers/google/tests/unit/google/cloud/utils/test_credentials_provider.py
@@ -28,6 +28,7 @@ from unittest.mock import ANY
 from uuid import uuid4
 
 import pytest
+from google.auth.credentials import Credentials
 from google.auth.environment_vars import CREDENTIALS
 from google.auth.exceptions import DefaultCredentialsError
 
@@ -541,6 +542,18 @@ class TestGetGcpCredentialsAndProjectId:
         mock_load_credentials_from_dict.assert_called_once()
         assert result == (mock_credentials, "")
 
+    @mock.patch("google.auth.load_credentials_from_file", autospec=True)
+    def test_get_credentials_using_credential_config_file_no_project_id(
+        self, mock_load_credentials_from_file
+    ):
+        mock_credentials = mock.create_autospec(Credentials, instance=True)
+        mock_load_credentials_from_file.return_value = (mock_credentials, None)
+
+        result = 
get_credentials_and_project_id(credential_config_file='{"type": 
"external_account"}')
+
+        mock_load_credentials_from_file.assert_called_once()
+        assert result == (mock_credentials, "")
+
 
 class TestGetScopes:
     def test_get_scopes_with_default(self):

Reply via email to