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

ephraimanierobi 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 f2e6452efd Removing magic status code numbers from api_connecxion 
(#24050)
f2e6452efd is described below

commit f2e6452efdf74828de9f73a8bf4f42f6dd10eb58
Author: Bernardo Couto <35502483+bernardoco...@users.noreply.github.com>
AuthorDate: Thu Jun 2 14:52:19 2022 -0300

    Removing magic status code numbers from api_connecxion (#24050)
---
 airflow/api_connexion/endpoints/config_endpoint.py          |  4 +++-
 airflow/api_connexion/endpoints/connection_endpoint.py      |  3 ++-
 airflow/api_connexion/endpoints/dag_endpoint.py             |  3 ++-
 airflow/api_connexion/endpoints/dag_run_endpoint.py         |  3 ++-
 airflow/api_connexion/endpoints/dag_source_endpoint.py      |  4 +++-
 airflow/api_connexion/endpoints/pool_endpoint.py            |  4 +++-
 .../api_connexion/endpoints/role_and_permission_endpoint.py |  3 ++-
 airflow/api_connexion/endpoints/user_endpoint.py            |  3 ++-
 airflow/api_connexion/endpoints/variable_endpoint.py        |  3 ++-
 airflow/api_connexion/exceptions.py                         | 13 +++++++------
 10 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/airflow/api_connexion/endpoints/config_endpoint.py 
b/airflow/api_connexion/endpoints/config_endpoint.py
index 9514621447..bdd2b3a959 100644
--- a/airflow/api_connexion/endpoints/config_endpoint.py
+++ b/airflow/api_connexion/endpoints/config_endpoint.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from http import HTTPStatus
+
 from flask import Response, request
 
 from airflow.api_connexion import security
@@ -72,7 +74,7 @@ def get_config() -> Response:
     }
     return_type = request.accept_mimetypes.best_match(serializer.keys())
     if return_type not in serializer:
-        return Response(status=406)
+        return Response(status=HTTPStatus.NOT_ACCEPTABLE)
     elif conf.getboolean("webserver", "expose_config"):
         conf_dict = conf.as_dict(display_source=False, display_sensitive=True)
         config = _conf_dict_to_config(conf_dict)
diff --git a/airflow/api_connexion/endpoints/connection_endpoint.py 
b/airflow/api_connexion/endpoints/connection_endpoint.py
index f9be9c227e..b196b3236b 100644
--- a/airflow/api_connexion/endpoints/connection_endpoint.py
+++ b/airflow/api_connexion/endpoints/connection_endpoint.py
@@ -16,6 +16,7 @@
 # under the License.
 
 import os
+from http import HTTPStatus
 
 from connexion import NoContent
 from flask import request
@@ -51,7 +52,7 @@ def delete_connection(*, connection_id: str, session: Session 
= NEW_SESSION) ->
             detail=f"The Connection with connection_id: `{connection_id}` was 
not found",
         )
     session.delete(connection)
-    return NoContent, 204
+    return NoContent, HTTPStatus.NO_CONTENT
 
 
 @security.requires_access([(permissions.ACTION_CAN_READ, 
permissions.RESOURCE_CONNECTION)])
diff --git a/airflow/api_connexion/endpoints/dag_endpoint.py 
b/airflow/api_connexion/endpoints/dag_endpoint.py
index e94707b127..0505f864ee 100644
--- a/airflow/api_connexion/endpoints/dag_endpoint.py
+++ b/airflow/api_connexion/endpoints/dag_endpoint.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from http import HTTPStatus
 from typing import Collection, Optional
 
 from connexion import NoContent
@@ -176,4 +177,4 @@ def delete_dag(dag_id: str, session: Session = NEW_SESSION) 
-> APIResponse:
     except AirflowException:
         raise AlreadyExists(detail=f"Task instances of dag with id: '{dag_id}' 
are still running")
 
-    return NoContent, 204
+    return NoContent, HTTPStatus.NO_CONTENT
diff --git a/airflow/api_connexion/endpoints/dag_run_endpoint.py 
b/airflow/api_connexion/endpoints/dag_run_endpoint.py
index 9fde3db885..e510126534 100644
--- a/airflow/api_connexion/endpoints/dag_run_endpoint.py
+++ b/airflow/api_connexion/endpoints/dag_run_endpoint.py
@@ -14,6 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from http import HTTPStatus
 from typing import List, Optional, Tuple
 
 import pendulum
@@ -62,7 +63,7 @@ def delete_dag_run(*, dag_id: str, dag_run_id: str, session: 
Session = NEW_SESSI
     """Delete a DAG Run"""
     if session.query(DagRun).filter(DagRun.dag_id == dag_id, DagRun.run_id == 
dag_run_id).delete() == 0:
         raise NotFound(detail=f"DAGRun with DAG ID: '{dag_id}' and DagRun ID: 
'{dag_run_id}' not found")
-    return NoContent, 204
+    return NoContent, HTTPStatus.NO_CONTENT
 
 
 @security.requires_access(
diff --git a/airflow/api_connexion/endpoints/dag_source_endpoint.py 
b/airflow/api_connexion/endpoints/dag_source_endpoint.py
index 74c3496a2c..ad6209221e 100644
--- a/airflow/api_connexion/endpoints/dag_source_endpoint.py
+++ b/airflow/api_connexion/endpoints/dag_source_endpoint.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from http import HTTPStatus
+
 from flask import Response, current_app, request
 from itsdangerous import BadSignature, URLSafeSerializer
 
@@ -42,4 +44,4 @@ def get_dag_source(*, file_token: str) -> Response:
     if return_type == 'application/json':
         content = dag_source_schema.dumps(dict(content=dag_source))
         return Response(content, headers={'Content-Type': return_type})
-    return Response("Not Allowed Accept Header", status=406)
+    return Response("Not Allowed Accept Header", 
status=HTTPStatus.NOT_ACCEPTABLE)
diff --git a/airflow/api_connexion/endpoints/pool_endpoint.py 
b/airflow/api_connexion/endpoints/pool_endpoint.py
index e9c8aee252..1d24fea63d 100644
--- a/airflow/api_connexion/endpoints/pool_endpoint.py
+++ b/airflow/api_connexion/endpoints/pool_endpoint.py
@@ -14,6 +14,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+
+from http import HTTPStatus
 from typing import Optional
 
 from flask import Response, request
@@ -41,7 +43,7 @@ def delete_pool(*, pool_name: str, session: Session = 
NEW_SESSION) -> APIRespons
     affected_count = session.query(Pool).filter(Pool.pool == 
pool_name).delete()
     if affected_count == 0:
         raise NotFound(detail=f"Pool with name:'{pool_name}' not found")
-    return Response(status=204)
+    return Response(status=HTTPStatus.NO_CONTENT)
 
 
 @security.requires_access([(permissions.ACTION_CAN_READ, 
permissions.RESOURCE_POOL)])
diff --git a/airflow/api_connexion/endpoints/role_and_permission_endpoint.py 
b/airflow/api_connexion/endpoints/role_and_permission_endpoint.py
index a25856e111..88a68341c1 100644
--- a/airflow/api_connexion/endpoints/role_and_permission_endpoint.py
+++ b/airflow/api_connexion/endpoints/role_and_permission_endpoint.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from http import HTTPStatus
 from typing import List, Optional, Tuple
 
 from connexion import NoContent
@@ -104,7 +105,7 @@ def delete_role(*, role_name: str) -> APIResponse:
     if not role:
         raise NotFound(title="Role not found", detail=f"Role with name 
{role_name!r} was not found")
     ab_security_manager.delete_role(role_name=role_name)
-    return NoContent, 204
+    return NoContent, HTTPStatus.NO_CONTENT
 
 
 @security.requires_access([(permissions.ACTION_CAN_EDIT, 
permissions.RESOURCE_ROLE)])
diff --git a/airflow/api_connexion/endpoints/user_endpoint.py 
b/airflow/api_connexion/endpoints/user_endpoint.py
index 82375cebca..6b4e984a69 100644
--- a/airflow/api_connexion/endpoints/user_endpoint.py
+++ b/airflow/api_connexion/endpoints/user_endpoint.py
@@ -14,6 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from http import HTTPStatus
 from typing import List, Optional
 
 from connexion import NoContent
@@ -204,4 +205,4 @@ def delete_user(*, username: str) -> APIResponse:
     security_manager.get_session.delete(user)
     security_manager.get_session.commit()
 
-    return NoContent, 204
+    return NoContent, HTTPStatus.NO_CONTENT
diff --git a/airflow/api_connexion/endpoints/variable_endpoint.py 
b/airflow/api_connexion/endpoints/variable_endpoint.py
index 067d163401..487d2cc486 100644
--- a/airflow/api_connexion/endpoints/variable_endpoint.py
+++ b/airflow/api_connexion/endpoints/variable_endpoint.py
@@ -14,6 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from http import HTTPStatus
 from typing import Optional
 
 from flask import Response, request
@@ -36,7 +37,7 @@ def delete_variable(*, variable_key: str) -> Response:
     """Delete variable"""
     if Variable.delete(variable_key) == 0:
         raise NotFound("Variable not found")
-    return Response(status=204)
+    return Response(status=HTTPStatus.NO_CONTENT)
 
 
 @security.requires_access([(permissions.ACTION_CAN_READ, 
permissions.RESOURCE_VARIABLE)])
diff --git a/airflow/api_connexion/exceptions.py 
b/airflow/api_connexion/exceptions.py
index 0c6c4fa0d3..8fb7f2e788 100644
--- a/airflow/api_connexion/exceptions.py
+++ b/airflow/api_connexion/exceptions.py
@@ -14,6 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from http import HTTPStatus
 from typing import Any, Dict, Optional
 
 import flask
@@ -80,7 +81,7 @@ class NotFound(ProblemException):
         **kwargs: Any,
     ) -> None:
         super().__init__(
-            status=404,
+            status=HTTPStatus.NOT_FOUND,
             type=EXCEPTIONS_LINK_MAP[404],
             title=title,
             detail=detail,
@@ -100,7 +101,7 @@ class BadRequest(ProblemException):
         **kwargs: Any,
     ) -> None:
         super().__init__(
-            status=400,
+            status=HTTPStatus.BAD_REQUEST,
             type=EXCEPTIONS_LINK_MAP[400],
             title=title,
             detail=detail,
@@ -120,7 +121,7 @@ class Unauthenticated(ProblemException):
         **kwargs: Any,
     ):
         super().__init__(
-            status=401,
+            status=HTTPStatus.UNAUTHORIZED,
             type=EXCEPTIONS_LINK_MAP[401],
             title=title,
             detail=detail,
@@ -140,7 +141,7 @@ class PermissionDenied(ProblemException):
         **kwargs: Any,
     ) -> None:
         super().__init__(
-            status=403,
+            status=HTTPStatus.FORBIDDEN,
             type=EXCEPTIONS_LINK_MAP[403],
             title=title,
             detail=detail,
@@ -160,7 +161,7 @@ class AlreadyExists(ProblemException):
         **kwargs: Any,
     ):
         super().__init__(
-            status=409,
+            status=HTTPStatus.CONFLICT,
             type=EXCEPTIONS_LINK_MAP[409],
             title=title,
             detail=detail,
@@ -180,7 +181,7 @@ class Unknown(ProblemException):
         **kwargs: Any,
     ) -> None:
         super().__init__(
-            status=500,
+            status=HTTPStatus.INTERNAL_SERVER_ERROR,
             type=EXCEPTIONS_LINK_MAP[500],
             title=title,
             detail=detail,

Reply via email to