Skip to content

Conversation

@maahir22
Copy link
Contributor

@maahir22 maahir22 commented Mar 28, 2023

This PR closes #26424
Problem Statement: The POST Request to the endpoint /api/v1/dags/~/dagRuns/~/taskInstances/list returns 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:

2023-03-28T17:16:17.637+0000 validation.py[200] None is not type object

@maahir22 maahir22 requested a review from ephraimbuddy as a code owner March 28, 2023 17:20
@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Mar 28, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 28, 2023

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)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

from flask import request

if not request.data:
raise BadRequest(detail="POST Body must not be None")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

@maahir22 maahir22 Apr 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the job is still failing, however I can't figure out where - do you see something wrong @uranusjr , @eladkal ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any updates on this?

Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
@maahir22 maahir22 requested a review from uranusjr April 11, 2023 16:34
Copy link
Contributor

@ephraimbuddy ephraimbuddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ephraimbuddy
Copy link
Contributor

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(

@uranusjr
Copy link
Member

uranusjr commented Apr 12, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /taskInstances/list with wildcards returns unhelpful error

3 participants