Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid execution_date crashes pages accepting the query parameter #22969

Closed
2 tasks done
tirkarthi opened this issue Apr 13, 2022 · 3 comments · Fixed by #23161
Closed
2 tasks done

Invalid execution_date crashes pages accepting the query parameter #22969

tirkarthi opened this issue Apr 13, 2022 · 3 comments · Fixed by #23161
Labels
area:webserver Webserver related Issues kind:bug This is a clearly a bug

Comments

@tirkarthi
Copy link
Contributor

Apache Airflow version

2.2.5 (latest released)

What happened

Invalid execution_date in query parameter will crash durations page since pendulum parsing exception is not handled in several views

What you think should happen instead

On ParseError the page should resort to some default value like in grid page or show an error flash message instead of crash.

How to reproduce

  1. Visit a dag duration page with invalid date in URL : http://localhost:8080/dags/raise_exception/duration?days=30&root=&num_runs=25&base_date=2022-04-12+16%3A29%3A21%2B05%3A30er
  2. Stacktrace
Python version: 3.10.4
Airflow version: 2.3.0.dev0
Node: laptop
-------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/pendulum/parsing/__init__.py", line 131, in _parse
    dt = parser.parse(
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 643, in parse
    raise ParserError("Unknown string format: %s", timestr)
dateutil.parser._parser.ParserError: Unknown string format: 2022-04-12 16:29:21+05:30er

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/karthikeyan/stuff/python/airflow/airflow/www/auth.py", line 40, in decorated
    return func(*args, **kwargs)
  File "/home/karthikeyan/stuff/python/airflow/airflow/www/decorators.py", line 80, in wrapper
    return f(*args, **kwargs)
  File "/home/karthikeyan/stuff/python/airflow/airflow/utils/session.py", line 71, in wrapper
    return func(*args, session=session, **kwargs)
  File "/home/karthikeyan/stuff/python/airflow/airflow/www/views.py", line 2870, in duration
    base_date = timezone.parse(base_date)
  File "/home/karthikeyan/stuff/python/airflow/airflow/utils/timezone.py", line 205, in parse
    return pendulum.parse(string, tz=timezone or TIMEZONE, strict=False)  # type: ignore
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/pendulum/parser.py", line 29, in parse
    return _parse(text, **options)
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/pendulum/parser.py", line 45, in _parse
    parsed = base_parse(text, **options)
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/pendulum/parsing/__init__.py", line 74, in parse
    return _normalize(_parse(text, **_options), **_options)
  File "/home/karthikeyan/stuff/python/airflow/.env/lib/python3.10/site-packages/pendulum/parsing/__init__.py", line 135, in _parse
    raise ParserError("Invalid date string: {}".format(text))
pendulum.parsing.exceptions.ParserError: Invalid date string: 2022-04-12 16:29:21+05:30er

Operating System

Ubuntu 20.04

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@tirkarthi tirkarthi added area:core kind:bug This is a clearly a bug labels Apr 13, 2022
@uranusjr uranusjr added area:webserver Webserver related Issues and removed area:core labels Apr 13, 2022
@uranusjr
Copy link
Member

FWIW this applies to all views accepting excution_date. Practically though, users are not supposed to manually write this parameter in, and Airflow never generates an invalid execution_date string, so all we need to do is to wrap the timezone.parse() call and return 400 if the input is invalid.

@uranusjr uranusjr changed the title Invalid execution_date in query parameter will crash dag's durations page Invalid execution_date crashes pages accepting the query parameter Apr 13, 2022
@tirkarthi
Copy link
Contributor Author

Agreed, it was a typo while copy pasting the link and I didn't expect a crash. Should we return a json response with error and status code as 400?

@uranusjr
Copy link
Member

No need to return a JSON, just a text/plain with a simple message saying execution_date is invalid. This is not going to be seen except by the more experienced users anyway, and those who are adventurous enough should be able to understand what’s going on from the short response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues kind:bug This is a clearly a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants