Opened 12 years ago

Closed 12 years ago

#19219 closed Bug (invalid)

Admin Templatetag log.py - context[self.user] is not an object

Reported by: scovetta Owned by: nobody
Component: contrib.admin Version: 1.4
Severity: Normal Keywords:
Cc: scovetta Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

I've recently upgraded to Django 1.4.2 and noticed that the Admin app is broken. Specifically, I am getting:

AttributeError: 'dict' object has no attribute 'id'

This is coming from:

# django/contrib/admin/templatetags/log.py
13	    def render(self, context):
14	        if self.user is None:
15	            context[self.varname] = LogEntry.objects.all().select_related('content_type', 'user')[:self.limit]
16	        else:
17	            user_id = self.user
18	            if not user_id.isdigit():
19				user_id = context[self.user].id

I am using some third-party components (Nexus and Django-Extensions, notably), but this looks like a bug within Django.

The context[self.user] variable is a dictionary, containing, a dict'ed User:

{'username': u'scovetta', 'first_name': u'', 'last_name': u'', 'is_active': True, '_state': <django.db.models.base.ModelState object at 0x104681c50>, 'email': u'', 'is_superuser': True, 'is_staff': True, 'last_login': datetime.datetime(2012, 10, 31, 11, 26, 53, 488934), 'password': u'(removed)' , 'id': 2, 'date_joined': datetime.datetime(2012, 8, 3, 8, 8, 59, 69517)  }

I've attached a patch for this.

Attachments (2)

log.py (2.2 KB ) - added by scovetta 12 years ago.
New log.py file
log.py.patch (189 bytes ) - added by scovetta 12 years ago.
Just the diff

Download all attachments as: .zip

Change History (4)

by scovetta, 12 years ago

Attachment: log.py added

New log.py file

by scovetta, 12 years ago

Attachment: log.py.patch added

Just the diff

comment:1 by scovetta, 12 years ago

Cc: scovetta added

comment:2 by Luke Plant, 12 years ago

Resolution: invalid
Status: newclosed

I assume the step to reproduce this is just going to the admin index, which uses the get_admin_log template tag, and it works fine.

It seems extremely likely that the third party components have broken something. In stock Django 1.4.2, context[self.user] is a django.contrib.auth.User object, wrapped with SimpleLazyObject.

I'm therefore closing this as invalid. It helps if you provide steps to reproduce a bug with stock Django.

Note: See TracTickets for help on using tickets.
Back to Top