10

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
DanT
  • 3,960
  • 5
  • 28
  • 33

4 Answers4

23

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

 # Instead of user.password = 'password'
 user._set_password = 'password'
Toni Piza
  • 505
  • 3
  • 11
13

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
DanT
  • 3,960
  • 5
  • 28
  • 33
  • Airflow _does_ set a version requirement on SQLA - it is set to `>=1.1` - it's just that SQLA made a backwards incompatible change between 1.1 and 1.2. And 1.2 was released more recently than Airflow has. – Ash Berlin-Taylor Feb 23 '18 at 15:40
  • True. Made a mistake when checking that, I'll edit the answer. Thanks. – DanT Feb 24 '18 at 12:55
  • Still, what would be the way sql alchemy recommends setting passwords? – thalesmello Mar 28 '18 at 07:22
1

Fixed with

pip install 'sqlalchemy<1.2'

I'm using apache-airflow 1.8.2

Feng Xu
  • 13
  • 3
0

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.

David White
  • 1,763
  • 2
  • 16
  • 27