Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#162 closed defect (fixed)

admin log accesses __repr__ too late (w/patch)

Reported by: mfenniak@… Owned by: Adrian Holovaty
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: no UI/UX: no

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("../../")

Change History (1)

comment:1 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

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

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