Sqlalchemy AttributeError:'NoneType'对象没有属性'_getter'

时间:2016-02-13 10:47:56

标签: python sqlalchemy

在我设置的实时系统中随机接收上述错误(平均每月一次)。问题是错误不会持续存在(即当我触摸app.wsgi文件时就会消失)因此很难确定导致问题的原因。它似乎失败的查询是登录时使用的第一个查询。 即。

user = db_session.query(Users).filter(Users.username == username, Users.password == password).first()

这在大多数情况下都可以正常工作,并且已经在单元测试中得到了解决。

完整的回溯错误如下:

[:error]     File "/path/to/my/python/file.py", line 23, in get_user_object
[:error]       user = db_session.query(Users).filter(Users.username == username, Users.password == password).first()
[:error]     File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2445, in first
[:error]       ret = list(self[0:1])
[:error]     File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2281, in __getitem__
[:error]       return list(res)
[:error]     File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/loading.py", line 84, in instances
[:error]       util.raise_from_cause(err)
[:error]     File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
[:error]       reraise(type(exception), exception, tb=exc_tb)
[:error]     File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/loading.py", line 51, in instances
[:error]       for query_entity in query._entities
[:error]     File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 3312, in row_processor
[:error]       polymorphic_discriminator=self._polymorphic_discriminator
[:error]     File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/loading.py", line 313, in _instance_processor
[:error]       getter = result._getter(col)
[:error]     File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/result.py", line 495, in _getter
[:error]       return self._metadata._getter(key)
[:error]   AttributeError: 'NoneType' object has no attribute '_getter'

1 个答案:

答案 0 :(得分:3)

通过执行

解决了问题
pip install sqlalchemy --upgrade
在给定的实时系统上,如rmn在评论中所建议的那样。