Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlalchemy AttributeError: 'NoneType' object has no attribute '_getter'

Receiving the above error randomly (so far once a month on average) in a live system I have set up. The problem is the error doesn't persist (i.e. goes away when I touch the app.wsgi file) so it's difficult to determine what's causing the problem. The query it seems to be failing on is the first one used on login. i.e.

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

This works fine the majority of the time, and has been covered in unittests.

The full traceback error is as follows:

[: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'
like image 879
Simon Melouah Avatar asked Feb 13 '16 10:02

Simon Melouah


1 Answers

The problem was resolved by doing a

pip install sqlalchemy --upgrade

on the given live system as suggested by rmn in the comments.

like image 197
Simon Melouah Avatar answered Nov 15 '22 12:11

Simon Melouah