IndexError: pop from empty list on request to /app

Issue #3 resolved
Bas ten Berge created an issue

Hi,

I'm running django-versioning version 0.7.4.6 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:

Environment:


Request Method: GET
Request URL: http://dev.brownpapersession.com:8000/app

Django Version: 1.6.2
Python Version: 2.6.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'south',
 'guardian',
 'organizations',
 'widget_tweaks',
 'allauth',
 'mailer',
 'haystack',
 'robots',
 'taggit',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.github',
 'allauth.socialaccount.providers.google',
 'allauth.socialaccount.providers.twitter',
 'allauth.socialaccount.providers.linkedin',
 'django_extensions',
 'axes',
 'app',
 'invite',
 'apporg',
 'versioning')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'versioning.middleware.VersioningMiddleware',
 'axes.middleware.FailedLoginMiddleware')

Traceback:
File "/var/www/brownpapersession/dev/env-brownpapersession/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  201.                 response = middleware_method(request, response)
File "/var/www/brownpapersession/dev/env-brownpapersession/lib/python2.6/site-packages/versioning/middleware.py" in process_response
  24.         transaction.commit()
File "/var/www/brownpapersession/dev/env-brownpapersession/lib/python2.6/site-packages/versioning/transaction.py" 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):
            return
        try:
            scope = self.scopes.pop()
            for obj in scope:
                self.post_save(obj)
        except IndexError:
            pass

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 https://bitbucket.org/emacsway/django-versioning/commits/afca21894c1f68b59cfb9e8e0ca8bf177855c38b?at=master#Lversioning/middleware.pyT24

    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 0.7.4.8

  2. Bas ten Berge reporter

    Ok, thanks. I guess it works as there's no error now and I've got version 0.7.4.9 installed

  3. Log in to comment