Code

#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 18 months ago.
New log.py file
log.py.patch (189 bytes) - added by scovetta 18 months ago.
Just the diff

Download all attachments as: .zip

Change History (4)

Changed 18 months ago by scovetta

New log.py file

Changed 18 months ago by scovetta

Just the diff

comment:1 Changed 18 months ago by scovetta

  • Cc scovetta added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 18 months ago by lukeplant

  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.