Airflow authentication setups fails with “AttributeError: can't set attribute”

风格不统一 提交于 2019-12-19 15:27:01

问题


The Airflow version 1.8 password authentication setup as described in the docs fails at the step

user.password = 'set_the_password'

with error

AttributeError: can't set attribute

回答1:


It's better to simply use the new method of PasswordUser _set_password:

 # Instead of user.password = 'password'
 user._set_password = 'password'



回答2:


This is due to an update of SqlAlchemy to a version >= 1.2 that introduced a backwards incompatible change.

You can fix this by explicitly installing a SqlAlchemy version <1.2.

pip install 'sqlalchemy<1.2'

Or in a requirement.txt

sqlalchemy<1.2



回答3:


Fixed with

pip install 'sqlalchemy<1.2'

I'm using apache-airflow 1.8.2




回答4:


In case anyone's curious about what the incompatible change in SQLAlchemy 1.2 (mentioned in @DanT's answer) actually is, it is a change in how SQLAlchemy deals with hybrid proprerties. Beginning in 1.2, methods have to have the same name as the original hybrid, which was not required before. The fix for Airflow is very simple. The code in contrib/auth/backends/password_auth.py should change from this:

@password.setter
    def _set_password(self, plaintext):
        self._password = generate_password_hash(plaintext, 12)
        if PY3:
            self._password = str(self._password, 'utf-8')

to this:

@password.setter
    def password(self, plaintext):
        self._password = generate_password_hash(plaintext, 12)
        if PY3:
            self._password = str(self._password, 'utf-8')

See https://bitbucket.org/zzzeek/sqlalchemy/issues/4332/hybrid_property-gives-attributeerror for more details.



来源:https://stackoverflow.com/questions/48075826/airflow-authentication-setups-fails-with-attributeerror-cant-set-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!