Opened 4 years ago

Closed 4 years ago

Last modified 4 years 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 by Mariusz Felisiak, 4 years ago

Easy pickings: set
Triage Stage: UnreviewedAccepted

Thanks for the report.

comment:2 by Mariusz Felisiak, 4 years ago

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

comment:3 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 63bbfa9f:

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

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 3fd82a62:

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

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