Opened 3 years ago
Closed 3 years ago
#33798 closed Uncategorized (invalid)
@cache_control test fails after upgrade to 4.0.5
| Reported by: | Matt Hegarty | Owned by: | nobody |
|---|---|---|---|
| Component: | Uncategorized | Version: | 4.0 |
| Severity: | Normal | Keywords: | cache_control decorator |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (4)
comment:1 by , 3 years ago
comment:2 by , 3 years ago
I believe issue introduced here:
https://github.com/django/django/commit/40165eecc40f9e223702a41a0cb0958515bb1f82
comment:3 by , 3 years ago
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')
comment:4 by , 3 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Hacking this fixes the test:
https://github.com/django/django/blob/d80a2585532ef15184afed6cf4ec1358198a894d/django/views/decorators/cache.py#L34