Opened 6 years ago

Closed 6 years ago

#19219 closed Bug (invalid)

Admin Templatetag - 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


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/
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) (2.2 KB) - added by scovetta 6 years ago.
New file (189 bytes) - added by scovetta 6 years ago.
Just the diff

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by scovetta

Attachment: added

New file

Changed 6 years ago by scovetta

Attachment: added

Just the diff

comment:1 Changed 6 years ago by scovetta

Cc: scovetta added

comment:2 Changed 6 years ago by Luke Plant

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