[Django] #33798: @cache_control test fails after upgrade to 4.0.5

12 views
Skip to first unread message

Django

unread,
Jun 22, 2022, 8:03:18 AM6/22/22
to django-...@googlegroups.com
#33798: @cache_control test fails after upgrade to 4.0.5
-------------------------------------+-------------------------------------
Reporter: Matt | Owner: nobody
Hegarty |
Type: | Status: new
Uncategorized |
Component: | Version: 4.0
Uncategorized | Keywords: cache_control
Severity: Normal | decorator
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
This worked ok in 3.2.13 - fails after upgrade to 4.0.5

Test:


{{{
class FaviconTests(SimpleTestCase):
def test_get(self):
response = self.client.get("/favicon.ico")
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertEqual(response["Cache-Control"], "max-age=86400,
immutable, public")
self.assertEqual(response["Content-Type"], "image/png")
content = b"".join(response.streaming_content)
self.assertGreater(len(content), 0)
}}}


View:

{{{
from django.conf import settings
from django.http import FileResponse
from django.views.decorators.cache import cache_control
from django.views.generic.base import View

class FaviconView(View):
@cache_control(max_age=60 * 60 * 24, immutable=True, public=True)
def get(self, request, *args, **kwargs):
file = (
settings.BASE_DIR / settings.STATIC_ROOT / "img" / "favicon-
32x32.png"
).open("rb")
return FileResponse(file)
}}}

Error:

TypeError: cache_control didn't receive an HttpRequest. If you are
decorating a classmethod, be sure to use @method_decorator.

--
Ticket URL: <https://code.djangoproject.com/ticket/33798>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 22, 2022, 8:12:46 AM6/22/22
to django-...@googlegroups.com
#33798: @cache_control test fails after upgrade to 4.0.5
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage:
decorator | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

Hacking this fixes the test:


{{{
if not hasattr(request.request, "META"):
}}}

https://github.com/django/django/blob/d80a2585532ef15184afed6cf4ec1358198a894d/django/views/decorators/cache.py#L34

--
Ticket URL: <https://code.djangoproject.com/ticket/33798#comment:1>

Django

unread,
Jun 22, 2022, 8:16:54 AM6/22/22
to django-...@googlegroups.com
#33798: @cache_control test fails after upgrade to 4.0.5
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage:
decorator | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

I believe issue introduced here:

https://github.com/django/django/commit/40165eecc40f9e223702a41a0cb0958515bb1f82

--
Ticket URL: <https://code.djangoproject.com/ticket/33798#comment:2>

Django

unread,
Jun 22, 2022, 8:28:08 AM6/22/22
to django-...@googlegroups.com
#33798: @cache_control test fails after upgrade to 4.0.5
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution:
Keywords: cache_control | Triage Stage:
decorator | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

OK, silly me. I should have paid more attention to the message. This
fixes it:


{{{
@method_decorator(cache_control(max_age=60 * 60 * 24, immutable=True,
public=True), name='dispatch')
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33798#comment:3>

Django

unread,
Jun 22, 2022, 8:28:31 AM6/22/22
to django-...@googlegroups.com
#33798: @cache_control test fails after upgrade to 4.0.5
-------------------------------------+-------------------------------------
Reporter: Matt Hegarty | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 4.0
Severity: Normal | Resolution: invalid

Keywords: cache_control | Triage Stage:
decorator | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Matt Hegarty):

* status: new => closed
* resolution: => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/33798#comment:4>

Reply all
Reply to author
Forward
0 new messages