<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Norwinter Studios &#187; sqlalchemy</title>
	<atom:link href="http://www.norwinter.com/tag/sqlalchemy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.norwinter.com</link>
	<description>Home of Bouncy Hunters and Konkret.</description>
	<lastBuildDate>Sat, 17 Jul 2010 20:38:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>SQLAlchemy 0.5.3 and 0.5.5 error: Set changed size during iteration</title>
		<link>http://www.norwinter.com/2009/08/03/sqlalchemy-0-5-3-and-0-5-5-error-set-changed-size-during-iteration/</link>
		<comments>http://www.norwinter.com/2009/08/03/sqlalchemy-0-5-3-and-0-5-5-error-set-changed-size-during-iteration/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 02:52:15 +0000</pubDate>
		<dc:creator>siker</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sqlalchemy]]></category>

		<guid isPermaLink="false">http://www.norwinter.com/?p=154</guid>
		<description><![CDATA[Update 1: See Mike Bayer&#8217;s comment below &#8211; looks like there&#8217;s a fix for this coming up in 0.5.6. Very responsive work by Mr. Bayer. Thanks! YippieMove has been running into some spurious problems with SQLAlchemy. When upgrading Python from 2.5 to 2.6 the errors became a lot more frequent. The error is &#8220;Set changed [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 1:</strong> See Mike Bayer&#8217;s comment below &#8211; looks like there&#8217;s a fix for this coming up in 0.5.6. Very responsive work by Mr. Bayer. Thanks!</p>
<p>YippieMove has been running into some spurious problems with SQLAlchemy. When upgrading Python from 2.5 to 2.6 the errors became a lot more frequent. The error is &#8220;<code>Set changed size during iteration</code>&#8221; and happens in all kinds of random code paths when using the ORM layer. Today I saw it happen when getting a result object from a query by index, and then again when iterating over the result of another query.</p>
<p>The end of the traceback looks something like this:</p>
<pre><code>
  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
</code></pre>
<p>The code in question looks like this:</p>
<pre><code>
    for state in self._mutable_attrs:
        if state.modified:
            return True
</code></pre>
<p>The program is single threaded and it sure didn&#8217;t look like &#8220;state.modified&#8221; would cause the iterated over set to change. Weird. After snooping around for a while I found <a href="http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg11283.html">this post</a> which suggests an async GC being the problem.</p>
<p>Sure enough the problem appears to have gone away when automatic GC is disabled. It&#8217;s not a nice workaround because the garbage collector in Python <a href="http://docs.python.org/library/gc.html">collects cyclic garbage</a>. But it did solve the problem for now so here it is if anyone else needs it:</p>
<pre><code>import gc
gc.disable()
</code></pre>
<p>Unless you want to be buried in garbage, make sure to collect it once in a while in a safe spot in your code using <code>gc.collect()</code>.</p>
<p>Hopefully this will be fixed in a future version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.norwinter.com/2009/08/03/sqlalchemy-0-5-3-and-0-5-5-error-set-changed-size-during-iteration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
