0

I have a pretty weird bug after upgrading to Django 1.5.. when I access my ClientDetailView with Django debug toolbar activated I get the following error:

Traceback:
File "/Users/mirkocrocop/.virtualenvs/upstream_backend/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  187.                 response = middleware_method(request, response)
File "/Users/mirkocrocop/.virtualenvs/upstream_backend/lib/python2.7/site-packages/debug_toolbar/panels/template.py" in process_response
  118.                     pformat(k(self.request))) for k in get_standard_processors()
File "/Users/mirkocrocop/workspace/upstream_backend/my_auth/context_processors.py" in extended_auth
  13.         user_groups = [g['name'] for g in tmp]
File "/Users/mirkocrocop/.virtualenvs/upstream_backend/lib/python2.7/site-packages/django/db/models/query.py" in _result_iter
  123.                 self._fill_cache()
File "/Users/mirkocrocop/.virtualenvs/upstream_backend/lib/python2.7/site-packages/django/db/models/query.py" in _fill_cache
  927.                     self._result_cache.append(next(self._iter))
File "/Users/mirkocrocop/.virtualenvs/upstream_backend/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  1004.         for row in self.query.get_compiler(self.db).results_iter():
File "/Users/mirkocrocop/.virtualenvs/upstream_backend/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
  775.         for rows in self.execute_sql(MULTI):
File "/Users/mirkocrocop/.virtualenvs/upstream_backend/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  840.         cursor.execute(sql, params)

Exception Type: InternalError at /clients/5/
Exception Value: current transaction is aborted, commands ignored until end of transaction block

… I know that sometimes I have to deactivate it to see what the real error is, but now if I deactivate DDT the error disappears completely. It shouldn't affect the production server but it's still pretty annoying.

Here's the view in question:

class BaseSingleClient(LoginRequiredMixin,
                       generic.detail.SingleObjectMixin):

    def get_context_data(self, **kwargs):
        '''
        Add the current client object to the context.
        This will be used in the template
        '''
        context = super(BaseSingleClient, self).get_context_data(**kwargs)
        try:
            self.client = self.kwargs['client_id']
        except KeyError, e:
            self.client = self.kwargs['pk']
        context['client_obj'] = UpstreamClientModel.objects.get(pk=
                                                                self.client)
        return context


class ClientDetailView(BaseSingleClient, generic.DetailView):
    model = UpstreamClientModel
    template_name = 'clients/client_detail.html'

And the SQL that is being executed at the time of the error:

DEBUG (0.004) SELECT "django_session"."session_key", "django_session"."session_data", "django_session"."expire_date" FROM "django_session" WHERE ("django_session"."session_key" = '0ayyigap4sphq5lvtlfy64una45o4id6'  AND "django_session"."expire_date" > '2013-05-27 10:38:44.800431+00:00' ); args=('0ayyigap4sphq5lvtlfy64una45o4id6', u'2013-05-27 10:38:44.800431+00:00')
DEBUG (0.002) SELECT "my_auth_profile"."id", "my_auth_profile"."password", "my_auth_profile"."last_login", "my_auth_profile"."is_superuser", "my_auth_profile"."username", "my_auth_profile"."first_name", "my_auth_profile"."last_name", "my_auth_profile"."email", "my_auth_profile"."is_staff", "my_auth_profile"."is_active", "my_auth_profile"."date_joined", "my_auth_profile"."cost_hour", "my_auth_profile"."last_activity" FROM "my_auth_profile" WHERE "my_auth_profile"."id" = 3 ; args=(3,)
DEBUG (0.001) SELECT "auth_group"."name" FROM "auth_group" INNER JOIN "my_auth_profile_groups" ON ("auth_group"."id" = "my_auth_profile_groups"."group_id") WHERE "my_auth_profile_groups"."profile_id" = 3 ; args=(3,)

This is where the last query comes from BTW:

my_auth.context_processors.py

def extended_auth(request):
    '''
    @allowed_user (bool) the user is either a Core team member or an admin.
    @user_groups (string) the groups the user belongs to.
    '''
    is_allowed = False
    user_groups = None
    if not request.user.is_anonymous():
        tmp = request.user.groups.values('name')
        user_groups = [g['name'] for g in tmp]
        if 'Core' in user_groups or 'Administrator' in user_groups:
            is_allowed = True
    return {'allowed_user': is_allowed, 'user_groups': user_groups, }
la_f0ka
  • 1,773
  • 3
  • 23
  • 44

1 Answers1

1

current transaction is aborted, commands ignored until end of transaction block tells you that a previous statement caused an error that resulted in an automatic transaction rollback.

You need to check your error logs for the previous statement that failed. Take a look at PostgreSQL's logs if you can't find it in Django's logs.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • I included the SQL statements executed. I tried them on their own and they return what's expected... is it something previous to that as well? – la_f0ka May 27 '13 at 12:45
  • @la_f0ka Yes, you need to find the *first* error in the transaction. It might help you to add the transaction ID or backend pid to the PostgreSQL log file prefix. – Craig Ringer May 27 '13 at 13:03
  • Awesome,... I was missing a table. Messed something up during migrations and didn't even notice. Go figure. Thanks! – la_f0ka May 27 '13 at 13:36
  • @la_f0ka Glad to help. Django should've aborted on the first error, not kept going, so consider reporting a bug against the error handling in the first place that had the error and ignored it. – Craig Ringer May 27 '13 at 13:38
  • For me this was Django Debug Toolbar being enabled and causing this same error – Kevin Parker Nov 22 '19 at 17:44