#32477: Wrapping of admin views does not preserve view attributes
-------------------------------+--------------------------------------
Reporter: Matt Pryor | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by Tim McCurrach):
Replying to [comment:2 Nick Pope]:
> It is unclear what your use case is for this change as you provide no
example of why you'd need to assign a custom attribute to a view.
>
> The current implementation, wrapping the function, is intended to
prevent side effects of modifying the original function when assigning the
`.model_admin` or `.admin_site` attributes.
I feel like I may be missing something here.
Since `admin_view` is itself a decorator, the function that we avoid
mutating is the function `inner` defined in `admin_view`. Why does it make
a difference if we mutate `inner` (from admin_view) or `wrapped` from
wrap? - neither are the original function!!
I agree, there needs to be some justification to add the proposed
capability (and none come to mind immediately). Nonetheless it feels like
the proposed PR is a simpler(better?) than what we have currently - and
just happens to have the additional upside that you can add custom
attributes to the view.
Looking back to the [https://github.com/django/django/commit/1f84630c87
original commit] where `get_urls` was added, `wrap` actually predates the
`.model_admin` and `.admin_site` attributes:
{{{
def wrap(view):
def wrapper(*args, **kwargs):
return self.admin_view(view)(*args, **kwargs)
return update_wrapper(wrapper, view)
}}}
I'm slightly lost as to why this was added at all, and why (as is
suggested in the docstring) self.admin_view didn't wrap the relevant views
directly).
I'm sure it was done this way for a good reason, I just can't see why. I
also apologise if this isn't the appropriate place to ask this question,
but I'm sure clarity as to why a ticket has been closed will be of use to
anyone proposing a similar change in the future.
--
Ticket URL: <https://code.djangoproject.com/ticket/32477#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/071.db6721dcb38fa5691223e3ea7406ad56%40djangoproject.com.