Fix POST /taskInstances/list with wildcards returns unhelpful error#30346
Fix POST /taskInstances/list with wildcards returns unhelpful error#30346maahir22 wants to merge 10 commits intoapache:mainfrom
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
6158114 to
3e7a39d
Compare
| from flask import request | ||
|
|
||
| if not request.data: | ||
| raise BadRequest(detail="POST Body must not be None") |
There was a problem hiding this comment.
| raise BadRequest(detail="POST Body must not be None") | |
| raise BadRequest(detail="POST Body must not be empty") |
Probably more neutral? The “None” part may not make sense for clients that are not implemented in Python.
There was a problem hiding this comment.
Fixed all static checks & even changed the error message. Think we should be good to go, can you please trigger the static workflow one more time?
There was a problem hiding this comment.
Any updates on this?
Co-authored-by: Ephraim Anierobi <[email protected]>
ephraimbuddy
left a comment
There was a problem hiding this comment.
Thinking about this more, It doesn't seem like we should fix it or fix it this way i.e ListTaskInstanceForm should not be updated to be nullable, it doesn't make sense to see on the documentation that the form can be null and still fail when user supply empty form
|
I prefer this hack: diff --git a/airflow/api_connexion/exceptions.py b/airflow/api_connexion/exceptions.py
index 11468e1506..8789ef8f39 100644
--- a/airflow/api_connexion/exceptions.py
+++ b/airflow/api_connexion/exceptions.py
@@ -41,7 +41,8 @@ EXCEPTIONS_LINK_MAP = {
def common_error_handler(exception: BaseException) -> flask.Response:
"""Used to capture connexion exceptions and add link to the type field."""
if isinstance(exception, ProblemException):
-
+ if exception.detail == "None is not of type 'object'":
+ exception.detail = "POST Body must not be empty"
link = EXCEPTIONS_LINK_MAP.get(exception.status)
if link:
response = problem( |
|
I read Connextion’s documentation and it actually allows us to customise the validator. I managed to make it emit an error message without hacks. See #30596. |
This PR closes #26424
Problem Statement: The POST Request to the endpoint
/api/v1/dags/~/dagRuns/~/taskInstances/listreturns an unhelpful error -> "detail": "None is not of type 'object'", when the JSON Body is empty. Upon further inspection, it seems that this error is raised by vaildation.py and is not handled properly leading to a generic error message and a Python Exception inside the logs.Fix: Allowing the request payload to be nullable and then checking if the data in the request is None before parsing it into JSON -> allows us to handle this error gracefully and even check for other unhandled cases.
New Response:
{ "detail": "['POST Body must not be None']", "status": 400, "title": "Bad Request", "type": "http://apache-airflow-docs.s3-website.eu-central-1.amazonaws.com/docs/apache-airflow/latest/stable-rest-api-ref.html#section/Errors/BadRequest" }Old Response:
{ "detail": "None is not of type 'object'", "status": 400, "title": "Bad Request", "type": "http://apache-airflow-docs.s3-website.eu-central-1.amazonaws.com/docs/apache-airflow/latest/stable-rest-api-ref.html#section/Errors/BadRequest" }Old Logs: