IndexError: pop from empty list on request to /app

Issue #3 resolved
Bas ten Berge
created an issue


I'm running django-versioning version in the django development server and I now get an IndexError when I try to get an app page. This is a GET request and there were no changes for as far as I know.

Here's exception detail:


Request Method: GET
Request URL:

Django Version: 1.6.2
Python Version: 2.6.6
Installed Applications:
Installed Middleware:

File "/var/www/brownpapersession/dev/env-brownpapersession/lib/python2.6/site-packages/django/core/handlers/" in get_response
  201.                 response = middleware_method(request, response)
File "/var/www/brownpapersession/dev/env-brownpapersession/lib/python2.6/site-packages/versioning/" in process_response
  24.         transaction.commit()
File "/var/www/brownpapersession/dev/env-brownpapersession/lib/python2.6/site-packages/versioning/" in commit
  35.         scope = self.scopes.pop()

Exception Type: IndexError at /app
Exception Value: pop from empty list

self.scopes is an empty list. I changed the commit method to this:

    def commit(self):
        """Commit transaction"""
        if self.locked(-1):
            scope = self.scopes.pop()
            for obj in scope:
        except IndexError:

I guess scope contains a list of entities that were changed?

Comments (5)

  1. Ivan Zakrevsky repo owner

    Thanks for message.

    I've fixed here

    Fix in transaction.commit() can mask other errors. For example, if transaction.commit() was called without transaction.begin().

    So, fix in middleware is preferred.

    The reason of bug is this, when raised exception, django calls both process_exception() and then process_response() (but scopes already is empty)

    Try version

  2. Log in to comment