【问题标题】:Airflow authentication setups fails with "AttributeError: can't set attribute"气流身份验证设置失败并显示“AttributeError:无法设置属性”
【发布时间】:2018-01-03 10:46:05
【问题描述】:

docs 中所述的 Airflow 1.8 版密码验证设置在该步骤失败

user.password = 'set_the_password'

有错误

AttributeError: can't set attribute

【问题讨论】:

    标签: airflow apache-airflow


    【解决方案1】:

    最好简单使用PasswordUser_set_password的新方法:

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

    【讨论】:

      【解决方案2】:

      这是由于将 SqlAlchemy 更新到 >= 1.2 的版本引入了向后不兼容的更改。

      您可以通过显式安装 SqlAlchemy 版本

      pip install 'sqlalchemy<1.2'
      

      或者在requirements.txt中

      sqlalchemy<1.2
      

      【讨论】:

      • Airflow 确实 对 SQLA 设置了版本要求 - 它设置为 &gt;=1.1 - 只是 SQLA 在 1.1 和 1.2 之间进行了向后不兼容的更改。而且 1.2 的发布时间比 Airflow 的发布时间要晚。
      • 是的。检查时出错,我将编辑答案。谢谢。
      • 不过,sql alchemy 建议设置密码的方式是什么?
      【解决方案3】:

      固定
      pip install 'sqlalchemy<1.2'
      

      我正在使用 apache-airflow 1.8.2

      【讨论】:

        【解决方案4】:

        如果有人对 SQLAlchemy 1.2 中的不兼容变化(在@DanT 的回答中提到)实际上 感到好奇,这是 SQLAlchemy 处理混合属性的方式的变化。从 1.2 开始,方法必须与原始混合具有相同的名称,这在以前是不需要的。 Airflow 的修复非常简单。 contrib/auth/backends/password_auth.py 中的代码应该从这里改变:

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

        到这里:

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

        更多详情请见https://bitbucket.org/zzzeek/sqlalchemy/issues/4332/hybrid_property-gives-attributeerror

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-02-08
          • 1970-01-01
          • 2021-11-23
          • 2014-08-09
          • 2021-04-15
          • 2022-11-18
          • 1970-01-01
          相关资源
          最近更新 更多