tabo/django-treebeard — pull request #9 by carljm (2013-06-27 19:35:33+00:00)
Title: Don't cache db connections on a model class.

Django 1.6 ensures thread-safe use of database connections by only allowing a database connection to be used in the thread that created it (https://github.com/django/django/blob/master/django/db/backends/__init__.py#L447). Treebeard's caching of db connections on the ``Node`` class means that sometimes connections will be used in the wrong thread, causing intermittent ``DatabaseError``s under a threaded webserver (such as ``runserver``). This pull request fixes that by simply removing the caching of connections and getting them from the router each time they are needed.

If this is a significant slowdown (I doubt it, but haven't benchmarked), the caching could be reintroduced, but needs to be keyed by thread ID.