Code

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#162 closed defect (fixed)

admin log accesses __repr__ too late (w/patch)

Reported by: mfenniak@… Owned by: adrian
Component: contrib.admin Version:
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If a meta.Model class has a repr function like this:

    def __repr__(self):
        return "Object #%s" % (self.id,)

When the object is deleted through the administration interface, the user interface shows that: The object "Object #None" was deleted successfully. A similar message appears in the admin log. It would suggest that the object's representation should be cached before it is deleted for display in the UI and logs.

This quick and simple patch fixes the problem:

Index: django/views/admin/main.py
===================================================================
--- django/views/admin/main.py  (revision 293)
+++ django/views/admin/main.py  (working copy)
@@ -1056,8 +1059,8 @@
     if request.POST: # The user has already confirmed the deletion.
         if perms_needed:
             raise PermissionDenied
+        obj_repr = repr(obj)
         obj.delete()
-        obj_repr = repr(obj)
         log.log_action(request.user.id, opts.get_content_type_id(), object_id, obj_repr, log.DELETION)
         request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr))
         return HttpResponseRedirect("../../")

Attachments (0)

Change History (1)

comment:1 Changed 9 years ago by adrian

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

(In [324]) Fixed #162 -- Admin log now records repr() before calling delete(), instead of after calling it() -- thanks, mfenniak@…!

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.