AttributeError: 'NoneType' object has no attribute 'pop'

2,349 views
Skip to first unread message

arashf

unread,
Nov 10, 2008, 8:28:41 PM11/10/08
to sqlalchemy
Traceback (most recent call last):
File "/srv/server/metaserver/metaserver/lib/base.py", line 56, in
__call__
ret = WSGIController.__call__(self, environ, start_response)
File "/usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/
controllers/core.py", line 195, in __call__
after = self._inspect_call(self.__after__)
wasn't getting this on the betas of sqlalchemy, but am getting it on
rc3. any ideas?

File "/usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/
controllers/core.py", line 79, in _inspect_call
result = func(**args)
File "/srv/server/metaserver/metaserver/lib/base.py", line 96, in
__after__
metaserver.model.Session.commit()
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
sqlalchemy/orm/scoping.py", line 121, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
sqlalchemy/orm/session.py", line 670, in commit
self.transaction.commit()
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
sqlalchemy/orm/session.py", line 385, in commit
self._remove_snapshot()
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
sqlalchemy/orm/session.py", line 306, in _remove_snapshot
_expire_state(s, None)
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc3-py2.5.egg/
sqlalchemy/orm/attributes.py", line 985, in expire_attributes
self.dict.pop(key, None)
AttributeError: 'NoneType' object has no attribute 'pop'

Michael Bayer

unread,
Nov 10, 2008, 8:57:56 PM11/10/08
to sqlal...@googlegroups.com
yeah this is an "enhancement" we made, whereby InstanceState removes
circular references from itself when its host object is garbage
collected, thereby taking the load off of gc (and it does). So in
this case, asynchronous gc is occurring right as InstanceState is
doing expire_attributes on itself, and the dict is getting swiped.
We had this issue and did a None check, but that's obviously not
enough since...well its asynchronous. So r5283 turns "state.dict"
into an attribute that will always spit out a dictionary if the "real"
one was removed, and its looking like rc4 will be sooner rather than
later as we are hitting a few glitches like this.

arashf

unread,
Nov 10, 2008, 10:36:56 PM11/10/08
to sqlalchemy
gotcha, cool. was I first to run into this? :-)

Michael Bayer

unread,
Nov 11, 2008, 10:49:32 AM11/11/08
to sqlal...@googlegroups.com
someone ran into a variant of it earlier, and we've had other variants
in the past.

ling...@gmail.com

unread,
Aug 21, 2020, 5:53:01 AM8/21/20
to sqlalchemy
AttributeError means that there was an Error that had to do with an Attribute request. In general, when you write x.y, y is the purported attribute of x. NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None. That usually means that an assignment or function call up failed or returned an unexpected result.

mylist = mylist.sort()

The sort() method of a list sorts the list in-place, that is, mylist is modified. But the actual return value of the method is None and not the list sorted. So you've just assigned None to mylist. If you next try to do, say, mylist.append(1) Python will give you this error.
Reply all
Reply to author
Forward
0 new messages