Opened 7 weeks ago

Closed 7 weeks ago

Last modified 7 weeks ago

#32468 closed Bug (fixed)

Admin never_cache decorators needs method_decorator

Reported by: hakib Owned by: hakib
Component: contrib.admin Version: 3.1
Severity: Normal Keywords: admin
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The login and logout views in Django's admin site are using the never_cache decorator, but they are both instance methods, so they need to use the method_decorator.

This is not a bug because the never_cache decorator is only operating on the response. The first argument to the decorator is supposed to be the request, but it is in-fact the admin_site instance (self). All the arguments are then passed to the view function and the decorator operate on the response.

If you try to use a different decorator that uses the request (such as required_http_methods) you will fail.

AttributeError: 'CustomAdminSite' object has no attribute 'method'

Related issue from long time ago:

https://code.djangoproject.com/ticket/18923

Change History (5)

comment:1 Changed 7 weeks ago by Mariusz Felisiak

Easy pickings: set
Triage Stage: UnreviewedAccepted

Thanks for the report.

comment:2 Changed 7 weeks ago by Mariusz Felisiak

Has patch: set
Owner: changed from nobody to hakib
Status: newassigned

comment:3 Changed 7 weeks ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin

comment:4 Changed 7 weeks ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 63bbfa9f:

Fixed #32468 -- Corrected usage of never_cache in contrib.admin.

comment:5 Changed 7 weeks ago by Mariusz Felisiak <felisiak.mariusz@…>

In 3fd82a62:

Refs #32468 -- Added error message on invalid usage of cache decorators.

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