-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Allow using Airflow with Flask CLI #9030
Conversation
airflow/www/app.py
Outdated
base_url = urlparse(conf.get('webserver', 'base_url'))[2] | ||
if not base_url or base_url == '/': | ||
base_url = "" | ||
flask_app.wsgi_app = DispatcherMiddleware(root_app, {base_url: flask_app.wsgi_app}) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual WSGI application. This is not implemented in
:meth:`__call__` so that middlewares can be applied without
losing a reference to the app object. Instead of doing this::
app = MyMiddleware(app)
It's a better idea to do this instead::
app.wsgi_app = MyMiddleware(app.wsgi_app)
Then you still have the original application object around and
can continue to call methods on it.
def create_app(config=None, testing=False, app_name="Airflow"): | ||
global app, appbuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes a side effect. We want the cache to be modified only by the cached_app method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
if not base_url or base_url == '/': | ||
base_url = "" | ||
if base_url: | ||
flask_app.wsgi_app = DispatcherMiddleware( # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This middleware is now optional. We use addresses in the form of blocked
which do not work properly with this middleware. This middleware expects the addresses to be in the form /blocked
. However, if we don't use this middleware, it doesn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove it then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use it in tests - test_views. This is still needed in production for some users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know FAB that well but it looks good and if we can use standard flask tools to interact with the app- that's fantastic. I'd love someone else to take a look at that, but for me itis LGTM
def create_app(config=None, testing=False, app_name="Airflow"): | ||
global app, appbuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
if not base_url or base_url == '/': | ||
base_url = "" | ||
if base_url: | ||
flask_app.wsgi_app = DispatcherMiddleware( # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove it then?
I still have to find one side effect because MySQL behaves differently than PostgresSQL. |
@@ -29,9 +29,6 @@ | |||
from airflow.configuration import conf | |||
from tests.test_utils.config import conf_vars | |||
|
|||
mock.patch('airflow.utils.cli.action_logging', lambda x: x).start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused a side effect. I don't know why it affected this change. Probably some session is now saving properly.
task2 = dag2.get_task(task_id='print_the_context') | ||
defaut_date2 = timezone.make_aware(datetime(2016, 1, 9)) | ||
dag2.clear() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may have data from another run.
@@ -201,7 +202,7 @@ def test_task_states_for_dag_run(self): | |||
tablefmt="plain") | |||
|
|||
# Check that prints, and log messages, are shown | |||
self.assertEqual(expected.replace("\n", ""), actual_out.replace("\n", "")) | |||
self.assertIn(expected.replace("\n", ""), actual_out.replace("\n", "")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the console, we have action_logger logs too.
@turbaszek I fixed the side effects. Can you look at it again? |
I wanna print all routes using FLASK CLI
This will facilitate the development of Airflow.
We also have other commands in CLI
Make sure to mark the boxes below before creating PR: [x]
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.