You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by bu...@apache.org on 2026/04/07 18:34:39 UTC
(airflow) branch main updated: Incorrect fallback logic (#64586)
This is an automated email from the ASF dual-hosted git repository.
bugraoz 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 fc315f3d77f Incorrect fallback logic (#64586)
fc315f3d77f is described below
commit fc315f3d77f4029c469ebc7d8be35983edcbfc27
Author: rjgoyln <15...@users.noreply.github.com>
AuthorDate: Wed Apr 8 02:34:30 2026 +0800
Incorrect fallback logic (#64586)
* Incorrect fallback logic
* Apply suggestions from code review
Co-authored-by: Copilot <17...@users.noreply.github.com>
---------
Co-authored-by: Copilot <17...@users.noreply.github.com>
---
airflow-ctl/src/airflowctl/api/client.py | 16 +++++++++++-----
airflow-ctl/tests/airflow_ctl/api/test_client.py | 18 +++++++++++++++++-
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/airflow-ctl/src/airflowctl/api/client.py b/airflow-ctl/src/airflowctl/api/client.py
index 1f6a9bfd25e..d66f385576b 100644
--- a/airflow-ctl/src/airflowctl/api/client.py
+++ b/airflow-ctl/src/airflowctl/api/client.py
@@ -236,11 +236,17 @@ class Credentials:
debug_creds_path = os.path.join(
default_config_dir, f"debug_creds_{self.input_cli_config_file}"
)
- with open(debug_creds_path) as df:
- debug_credentials = json.load(df)
- self.api_token = debug_credentials.get(
- self.token_key_for_environment(self.api_environment)
- )
+ try:
+ with open(debug_creds_path) as df:
+ debug_credentials = json.load(df)
+ self.api_token = debug_credentials.get(self.token_key_for_environment(self.api_environment))
+ except FileNotFoundError as e:
+ if self.client_kind == ClientKind.CLI:
+ raise AirflowCtlCredentialNotFoundException(
+ f"Debug credentials file not found: {debug_creds_path}. "
+ "Set AIRFLOW_CLI_DEBUG_MODE=false or log in with debug mode enabled first."
+ ) from e
+ self.api_token = None
else:
try:
self.api_token = keyring.get_password(
diff --git a/airflow-ctl/tests/airflow_ctl/api/test_client.py b/airflow-ctl/tests/airflow_ctl/api/test_client.py
index 0617d62276a..f495b357d8d 100644
--- a/airflow-ctl/tests/airflow_ctl/api/test_client.py
+++ b/airflow-ctl/tests/airflow_ctl/api/test_client.py
@@ -30,7 +30,10 @@ from httpx import URL
from airflowctl.api.client import Client, ClientKind, Credentials, _bounded_get_new_password
from airflowctl.api.operations import ServerResponseError
-from airflowctl.exceptions import AirflowCtlCredentialNotFoundException, AirflowCtlKeyringException
+from airflowctl.exceptions import (
+ AirflowCtlCredentialNotFoundException,
+ AirflowCtlKeyringException,
+)
def make_client_w_responses(responses: list[httpx.Response]) -> Client:
@@ -376,3 +379,16 @@ class TestSaveKeyringPatching:
response = client.get("http://error")
assert response.status_code == 200
assert len(responses) == 1
+
+ def test_debug_mode_missing_debug_creds_reports_correct_error(self, monkeypatch, tmp_path):
+ monkeypatch.setenv("AIRFLOW_HOME", str(tmp_path))
+ monkeypatch.setenv("AIRFLOW_CLI_DEBUG_MODE", "true")
+ monkeypatch.setenv("AIRFLOW_CLI_ENVIRONMENT", "TEST_DEBUG")
+
+ config_path = tmp_path / "TEST_DEBUG.json"
+ config_path.write_text(json.dumps({"api_url": "http://localhost:8080"}), encoding="utf-8")
+ # Intentionally do not create debug_creds_TEST_DEBUG.json to simulate a missing file
+
+ creds = Credentials(client_kind=ClientKind.CLI, api_environment="TEST_DEBUG")
+ with pytest.raises(AirflowCtlCredentialNotFoundException, match="Debug credentials file not found"):
+ creds.load()