Garbage collection causes spurious Set changed size during iteration errors.

Issue #1493 resolved
Former user created an issue

The following abbreviated stack trace shows a spurious error happening with SQLAlchemy. Tested with SQLAlchemy 0.5.3 and Python 2.5 and SQLAlchemy 0.5.5 with Python 2.6.

  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/dynamic.py", line 192, in __iter__
    sess = self.__session()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/dynamic.py", line 181, in __session
    sess.flush()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/session.py", line 1354, in flush
    self._flush(objects)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/session.py", line 1359, in _flush
    if (not self.identity_map.check_modified() and
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/orm/identity.py", line 56, in check_modified
    for state in self._mutable_attrs:
RuntimeError: Set changed size during iteration

The work around is to turn off garbage collection with gc.disable().

To take a guess at what's wrong, self._mutable_attrs probably contains weak reference elements that may disappear during garbage collection which breaks the iteration.

I posted some additional information here:

http://www.norwinter.com/2009/08/03/sqlalchemy-0-5-3-and-0-5-5-error-set-changed-size-during-iteration/

Comments (2)

  1. Log in to comment