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

你说的曾经没有我的故事 提交于 2019-12-01 15:55:00

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

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

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

Fixed with

pip install 'sqlalchemy<1.2'

I'm using apache-airflow 1.8.2

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.

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