[ 
https://issues.apache.org/jira/browse/AIRFLOW-2117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16504687#comment-16504687
 ] 

Matthias Huschle commented on AIRFLOW-2117:
-------------------------------------------

I ran into the same issue when experimenting with proper authentication (due to 
the recent discussion on security by default). The reason seems to be that I'm 
using an environment with a more recent version of flask_login.

Airflow officially requires flask-login==0.2.11, which I don't want to go back 
to for reasons. Version 0.3.0 had breaking changes (see 
[https://github.com/maxcountryman/flask-login/blob/master/CHANGES),] making 
properties out of the functions is_active, is_authenticated and is_anonymous.

Changing the views.py or utils.py might work, if one also changes the 
respective members of the PasswordUser class (haven't tried). However, this 
requires changes in many places and would not allow to retain compatibility 
with previous versions of flask_login in a simple way.

My approach was to instead change those members in the PasswordUser class to 
hybrid-objects, that evaluate to the same value if cast as bool or called as 
function, so they should work with pre- and post 0.3.0, and all changes are in 
password_auth.py. In addition, it was necessary to introduce a custom class for 
anonymous users, that the login manager falls back to if no user is logged in.

I don't know whether this is a valid option for the master branch, but it works 
for me pretty well so far:

[https://github.com/matthiashuschle/airflow/commit/cc1abd04ae20294c93ff47ef6465ac7b86a4196c]

> Unable to login to webserver
> ----------------------------
>
>                 Key: AIRFLOW-2117
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-2117
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: webserver
>    Affects Versions: 1.9.0
>            Reporter: Brian Hoover
>            Priority: Major
>
> Unable to login to webserver after upgrade to 1.9.  
> Worth noting is that if I modify 
> '/usr/local/lib/python3.5/dist-packages/airflow/www/utils.py' and change the 
> calls to the following:
> current_user.is_anonymous,
> current_user.is_authenticated,
> current_user.is_superuser,
> current_user.data_profiling
> and remove the parenthesis, I am able to log in.  However, I am then unable 
> to see many of the menu items at the top of UI.
> Once logged in, I can revert those changes and am able to see the menu items 
> again.
> Here is the reported error:
> -------------------------------------------------------------------------------
> Node: localhost
> -------------------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1982, in 
> wsgi_app
>     response = self.full_dispatch_request()
>   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1614, in 
> full_dispatch_request
>     rv = self.handle_user_exception(e)
>   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1517, in 
> handle_user_exception
>     reraise(exc_type, exc_value, tb)
>   File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in 
> reraise
>     raise value
>   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1612, in 
> full_dispatch_request
>     rv = self.dispatch_request()
>   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1598, in 
> dispatch_request
>     return self.view_functions[rule.endpoint](**req.view_args)
>   File "/usr/local/lib/python3.5/dist-packages/flask_admin/base.py", line 69, 
> in inner
>     return self._run_view(f, *args, **kwargs)
>   File "/usr/local/lib/python3.5/dist-packages/flask_admin/base.py", line 
> 368, in _run_view
>     return fn(self, *args, **kwargs)
>   File "/usr/local/lib/python3.5/dist-packages/airflow/www/views.py", line 
> 645, in login
>     return airflow.login.login(self, request)
>   File 
> "/usr/local/lib/python3.5/dist-packages/airflow/contrib/auth/backends/password_auth.py",
>  line 124, in login
>     form=form)
>   File "/usr/local/lib/python3.5/dist-packages/flask_admin/base.py", line 
> 308, in render
>     return render_template(template, **kwargs)
>   File "/usr/local/lib/python3.5/dist-packages/flask/templating.py", line 
> 134, in render_template
>     context, ctx.app)
>   File "/usr/local/lib/python3.5/dist-packages/flask/templating.py", line 
> 116, in _render
>     rv = template.render(context)
>   File "/usr/local/lib/python3.5/dist-packages/jinja2/environment.py", line 
> 1008, in render
>     return self.environment.handle_exception(exc_info, True)
>   File "/usr/local/lib/python3.5/dist-packages/jinja2/environment.py", line 
> 780, in handle_exception
>     reraise(exc_type, exc_value, tb)
>   File "/usr/local/lib/python3.5/dist-packages/jinja2/_compat.py", line 37, 
> in reraise
>     raise value.with_traceback(tb)
>   File 
> "/usr/local/lib/python3.5/dist-packages/airflow/www/templates/airflow/login.html",
>  line 18, in top-level template code
>     {% extends "airflow/master.html" %}
>   File 
> "/usr/local/lib/python3.5/dist-packages/airflow/www/templates/airflow/master.html",
>  line 18, in top-level template code
>     {% extends "admin/master.html" %}
>   File 
> "/usr/local/lib/python3.5/dist-packages/airflow/www/templates/admin/master.html",
>  line 18, in top-level template code
>     {% extends 'admin/base.html' %}
>   File 
> "/usr/local/lib/python3.5/dist-packages/flask_admin/templates/bootstrap3/admin/base.html",
>  line 37, in top-level template code
>     {% block page_body %}
>   File 
> "/usr/local/lib/python3.5/dist-packages/airflow/www/templates/admin/master.html",
>  line 74, in block "page_body"
>     {% block main_menu %}
>   File 
> "/usr/local/lib/python3.5/dist-packages/airflow/www/templates/admin/master.html",
>  line 76, in block "main_menu"
>     {{ layout.menu() }}
>   File "/usr/local/lib/python3.5/dist-packages/jinja2/runtime.py", line 579, 
> in _invoke
>     rv = self._func(*arguments)
>   File 
> "/usr/local/lib/python3.5/dist-packages/flask_admin/templates/bootstrap3/admin/layout.html",
>  line 21, in template
>     {% set children = item.get_children() %}
>   File "/usr/local/lib/python3.5/dist-packages/flask_admin/menu.py", line 52, 
> in get_children
>     return [c for c in self._children if c.is_accessible() and c.is_visible()]
>   File "/usr/local/lib/python3.5/dist-packages/flask_admin/menu.py", line 52, 
> in <listcomp>
>     return [c for c in self._children if c.is_accessible() and c.is_visible()]
>   File "/usr/local/lib/python3.5/dist-packages/flask_admin/menu.py", line 
> 126, in is_accessible
>     return self._view.is_accessible()
>   File "/usr/local/lib/python3.5/dist-packages/airflow/www/utils.py", line 
> 75, in is_accessible
>     (not current_user.is_anonymous() and current_user.data_profiling())
> TypeError: 'bool' object is not callable



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to