Stores don't rollback correctly in Django

Bug #495169 reported by Anthony Lenton
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
New
Undecided
Unassigned

Bug Description

When using storm as a Django db backend, if you have to rollback a store due to a database disconnection, the connection isn't set up again properly. Here's a short example using Django's interactive shell:

$ python manage.py shell
Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> # My STORM_STORES is {'data': 'postgres://postgres@localhost/foobar'}
>>> from django.db import connection
>>> cur = connection.cursor()
>>> # Before continuing, restart the database so that the connection is stale
>>> cur.execute('select true')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "(...)/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
OperationalError: terminating connection due to administrator command
server closed the connection unexpectedly
 This probably means the server terminated abnormally
 before or while processing the request.

>>> # As expected, that failed. So let's rollback...
>>> connection._store.rollback()
>>> cur = connection.cursor()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "(...)/django/db/backends/__init__.py", line 56, in cursor
    cursor = self._cursor(settings)
  File "(...)/storm/django/backend/base.py", line 30, in _cursor
    cursor = super(StormDatabaseWrapperMixin, self)._cursor(*args)
  File "(...)/django/db/backends/postgresql_psycopg2/base.py", line 84, in _cursor
    self.connection = Database.connect(conn_string, **self.options)
OperationalError: FATAL: database "data" does not exist

At this point it shouldn't be trying to connect in line 84 of django/db/backends/postgresql_psycopg2/base.py, as storm should already have set up a connection for it when it reaches line 70. The code on line 84 of base.py should never be run while using the storm backend, as it uses the DATABASE_* settings that storm replaces with STORM_STORES.

Or am I doing it wrong? :)

Revision history for this message
James Henstridge (jamesh) wrote :

Looks like StormDatabaseWrapperMixin._get_connection() should include a call to self._store._connection._ensure_connected().

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.