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

Replace FAB url filtering function with Airflows #27576

Merged
merged 2 commits into from Nov 9, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions airflow/www/extensions/init_appbuilder.py
Expand Up @@ -215,13 +215,24 @@ def init_app(self, app, session):
else:
self.post_init()
self._init_extension(app)
self._swap_url_filter()

def _init_extension(self, app):
app.appbuilder = self
if not hasattr(app, "extensions"):
app.extensions = {}
app.extensions["appbuilder"] = self

def _swap_url_filter(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

A side comment (not related to the test failure):

why is the private method of a class altering the global object? The content of this method doesn't use the actual object it is called upon (self) and yet this method is called as part of initialization of the AirflowAppBuilder object.

Does the builder depends on the old behavior of fab_sec_views.get_safe_redirect before initialization complete? If so, could you please leave a comment about that? If not, is the AppBuilder (which focuses on building "app" object) the right place to perform this substitution? Maybe it would be better to put static part of the initialization in a new dedicated file?

"""
Use our url filtering util function so there is consistency between
FAB and Airflow routes
"""
from flask_appbuilder.security import views as fab_sec_views
jedcunningham marked this conversation as resolved.
Show resolved Hide resolved
from airflow.www.views import get_safe_url

fab_sec_views.get_safe_redirect = get_safe_url

def post_init(self):
for baseview in self.baseviews:
# instantiate the views and add session
Expand Down