This is an automated email from the ASF dual-hosted git repository.
pierrejeambrun 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 5b255dcab7 Fix webserver crash when calling get /config (#31057)
5b255dcab7 is described below
commit 5b255dcab7f488601fd3d31e9be2ae70b7dea483
Author: Pankaj Singh <[email protected]>
AuthorDate: Fri May 5 05:53:12 2023 +0530
Fix webserver crash when calling get /config (#31057)
currently, if the section is not found we raise AirflowNotFoundException
and that does not handle returning response gracefully and the web server
crash
I think the right expectation to raise here should be NotFound
---
airflow/api_connexion/endpoints/config_endpoint.py | 3 +--
airflow/api_connexion/openapi/v1.yaml | 3 ++-
airflow/www/static/js/types/api-generated.ts | 1 +
tests/api_connexion/endpoints/test_config_endpoint.py | 11 +++++++++++
4 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/airflow/api_connexion/endpoints/config_endpoint.py
b/airflow/api_connexion/endpoints/config_endpoint.py
index 880322b188..b7bb81194b 100644
--- a/airflow/api_connexion/endpoints/config_endpoint.py
+++ b/airflow/api_connexion/endpoints/config_endpoint.py
@@ -24,7 +24,6 @@ from airflow.api_connexion import security
from airflow.api_connexion.exceptions import NotFound, PermissionDenied
from airflow.api_connexion.schemas.config_schema import Config, ConfigOption,
ConfigSection, config_schema
from airflow.configuration import conf
-from airflow.exceptions import AirflowNotFoundException
from airflow.security import permissions
from airflow.settings import json
@@ -79,7 +78,7 @@ def get_config(*, section: str | None = None) -> Response:
return Response(status=HTTPStatus.NOT_ACCEPTABLE)
elif conf.getboolean("webserver", "expose_config"):
if section and not conf.has_section(section):
- raise AirflowNotFoundException(f"section={section} not found")
+ raise NotFound("section not found.", detail=f"section={section}
not found.")
conf_dict = conf.as_dict(display_source=False, display_sensitive=True)
if section:
conf_section_value = conf_dict[section]
diff --git a/airflow/api_connexion/openapi/v1.yaml
b/airflow/api_connexion/openapi/v1.yaml
index 71eb0b4a99..598af492b8 100644
--- a/airflow/api_connexion/openapi/v1.yaml
+++ b/airflow/api_connexion/openapi/v1.yaml
@@ -1994,11 +1994,12 @@ paths:
smtp_host = localhost
smtp_mail_from = [email protected]
-
'401':
$ref: '#/components/responses/Unauthenticated'
'403':
$ref: '#/components/responses/PermissionDenied'
+ '404':
+ $ref: '#/components/responses/NotFound'
/config/section/{section}/option/{option}:
get:
diff --git a/airflow/www/static/js/types/api-generated.ts
b/airflow/www/static/js/types/api-generated.ts
index 5447fb5639..4f2977fb27 100644
--- a/airflow/www/static/js/types/api-generated.ts
+++ b/airflow/www/static/js/types/api-generated.ts
@@ -4197,6 +4197,7 @@ export interface operations {
};
401: components["responses"]["Unauthenticated"];
403: components["responses"]["PermissionDenied"];
+ 404: components["responses"]["NotFound"];
};
};
get_value: {
diff --git a/tests/api_connexion/endpoints/test_config_endpoint.py
b/tests/api_connexion/endpoints/test_config_endpoint.py
index 7b0c6f1154..1233c24e8d 100644
--- a/tests/api_connexion/endpoints/test_config_endpoint.py
+++ b/tests/api_connexion/endpoints/test_config_endpoint.py
@@ -143,6 +143,17 @@ class TestGetConfig:
}
assert expected == response.json
+ @patch("airflow.api_connexion.endpoints.config_endpoint.conf.as_dict",
return_value=MOCK_CONF)
+ def test_should_respond_404_when_section_not_exist(self, mock_as_dict):
+ response = self.client.get(
+ "/api/v1/config?section=smtp1",
+ headers={"Accept": "application/json"},
+ environ_overrides={"REMOTE_USER": "test"},
+ )
+
+ assert response.status_code == 404
+ assert "section=smtp1 not found." in response.json["detail"]
+
@patch("airflow.api_connexion.endpoints.config_endpoint.conf.as_dict",
return_value=MOCK_CONF)
def test_should_respond_406(self, mock_as_dict):
response = self.client.get(