This is an automated email from the ASF dual-hosted git repository.

henry3260 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 2240e9132df Report the missing secret id when Google get_secret raises 
NotFound (#73035)
2240e9132df is described below

commit 2240e9132df118c884ba44f178bd9c0c08079ba5
Author: rjgoyln <[email protected]>
AuthorDate: Tue Sep 15 16:13:17 2026 +0800

    Report the missing secret id when Google get_secret raises NotFound (#73035)
    
    NotFound comes from google.api_core, whose constructor signature is
    (message, errors=(), ...) and whose __str__ renders only the code and the
    message. Passing the secret id as a second positional argument bound it
    to errors instead of interpolating it, so the error read
    "404 The secret '%s' not found" and the one piece of information a user
    needs in order to act on it never reached them.
    
    The system test Dag reached the same raise through a copy of the helper,
    so it now goes through the shared one rather than gaining a second
    definition that would have to be kept in step.
---
 .../src/airflow/providers/google/common/utils/get_secret.py   |  3 ++-
 providers/google/tests/system/google/ads/example_ads.py       | 11 +----------
 .../google/tests/unit/google/common/utils/test_get_secret.py  |  2 +-
 3 files changed, 4 insertions(+), 12 deletions(-)

diff --git 
a/providers/google/src/airflow/providers/google/common/utils/get_secret.py 
b/providers/google/src/airflow/providers/google/common/utils/get_secret.py
index 0ae00513e99..9122d12add1 100644
--- a/providers/google/src/airflow/providers/google/common/utils/get_secret.py
+++ b/providers/google/src/airflow/providers/google/common/utils/get_secret.py
@@ -28,4 +28,5 @@ def get_secret(secret_id: str) -> str:
     hook = GoogleCloudSecretManagerHook()
     if hook.secret_exists(secret_id=secret_id):
         return hook.access_secret(secret_id=secret_id).payload.data.decode()
-    raise NotFound("The secret '%s' not found", secret_id)
+    msg = f"The secret '{secret_id}' not found"
+    raise NotFound(msg)
diff --git a/providers/google/tests/system/google/ads/example_ads.py 
b/providers/google/tests/system/google/ads/example_ads.py
index 9192e2ae276..17106e1625d 100644
--- a/providers/google/tests/system/google/ads/example_ads.py
+++ b/providers/google/tests/system/google/ads/example_ads.py
@@ -38,8 +38,6 @@ import logging
 import os
 from datetime import datetime
 
-from google.cloud.exceptions import NotFound
-
 try:
     from airflow.sdk import task
 except ImportError:
@@ -48,8 +46,8 @@ except ImportError:
 from airflow.models.dag import DAG
 from airflow.providers.google.ads.operators.ads import 
GoogleAdsListAccountsOperator
 from airflow.providers.google.ads.transfers.ads_to_gcs import 
GoogleAdsToGcsOperator
-from airflow.providers.google.cloud.hooks.secret_manager import 
GoogleCloudSecretManagerHook
 from airflow.providers.google.cloud.operators.gcs import 
GCSCreateBucketOperator, GCSDeleteBucketOperator
+from airflow.providers.google.common.utils.get_secret import get_secret
 
 try:
     from airflow.sdk import TriggerRule
@@ -114,13 +112,6 @@ FIELDS_TO_EXTRACT = [
 log = logging.getLogger(__name__)
 
 
-def get_secret(secret_id: str) -> str:
-    hook = GoogleCloudSecretManagerHook()
-    if hook.secret_exists(secret_id=secret_id):
-        return hook.access_secret(secret_id=secret_id).payload.data.decode()
-    raise NotFound("The secret '%s' not found", secret_id)
-
-
 with DAG(
     DAG_ID,
     schedule="@once",
diff --git a/providers/google/tests/unit/google/common/utils/test_get_secret.py 
b/providers/google/tests/unit/google/common/utils/test_get_secret.py
index 7faa13b38ac..2c819060662 100644
--- a/providers/google/tests/unit/google/common/utils/test_get_secret.py
+++ b/providers/google/tests/unit/google/common/utils/test_get_secret.py
@@ -58,7 +58,7 @@ class TestGetSecret:
 
         secret_id = "non-existent-secret"
 
-        with pytest.raises(NotFound):
+        with pytest.raises(NotFound, match=f"The secret '{secret_id}' not 
found"):
             get_secret(secret_id=secret_id)
 
         mock_hook_class.assert_called_once()

Reply via email to