@cache_control decorator fails after update to 4.0.5

Skip to first unread message

Matthew Hegarty

Jun 22, 2022, 7:51:18 AMJun 22
to Django users
Hi All

I'm upgrading to 4.0.5 from 3.2.13

My integration test fails:

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)

Error is:

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

Can anyone advise if this is a known issue?


Matthew Hegarty

Jun 22, 2022, 8:29:25 AMJun 22
to Django users

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')
Reply all
Reply to author
0 new messages