DanT
DanT

Reputation: 4180

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

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

Upvotes: 10

Views: 4574

Answers (4)

David White
David White

Reputation: 1863

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.

Upvotes: 0

DanT
DanT

Reputation: 4180

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

Upvotes: 13

Toni Piza
Toni Piza

Reputation: 515

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

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

Upvotes: 23

Feng Xu
Feng Xu

Reputation: 13

Fixed with

pip install 'sqlalchemy<1.2'

I'm using apache-airflow 1.8.2

Upvotes: 1

Related Questions