From f52c780d16d0d06ae996b1f9a159b1b6c66808b2 Mon Sep 17 00:00:00 2001 From: Vince Salvino Date: Wed, 21 Aug 2024 17:16:57 -0400 Subject: [PATCH 1/2] Support Django 5.1 (#76) Refactor cache middleware to be compliant with Django API (fixes bug caused by Django 5.1). Fixes #74. --------- Co-authored-by: Anthony Uphof <44126722+auphof@users.noreply.github.com> Co-authored-by: Gwendolyn --- wagtailcache/cache.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wagtailcache/cache.py b/wagtailcache/cache.py index 0d92c75..460023c 100644 --- a/wagtailcache/cache.py +++ b/wagtailcache/cache.py @@ -183,10 +183,9 @@ class FetchFromCacheMiddleware(MiddlewareMixin): Mostly stolen from ``django.middleware.cache.FetchFromCacheMiddleware``. """ - def __init__(self, get_response=None): + def __init__(self, get_response): self._wagcache = caches[wagtailcache_settings.WAGTAIL_CACHE_BACKEND] - self.get_response = get_response - self._async_check() + super().__init__(get_response) def process_request(self, request: WSGIRequest) -> Optional[HttpResponse]: if not wagtailcache_settings.WAGTAIL_CACHE: @@ -250,10 +249,9 @@ class UpdateCacheMiddleware(MiddlewareMixin): Mostly stolen from ``django.middleware.cache.UpdateCacheMiddleware``. """ - def __init__(self, get_response=None): + def __init__(self, get_response): self._wagcache = caches[wagtailcache_settings.WAGTAIL_CACHE_BACKEND] - self.get_response = get_response - self._async_check() + super().__init__(get_response) def process_response( self, request: WSGIRequest, response: HttpResponse @@ -411,13 +409,15 @@ def _wrapped_view_func( request: WSGIRequest, *args, **kwargs ) -> HttpResponse: # Try to fetch an already cached page from wagtail-cache. - response = FetchFromCacheMiddleware().process_request(request) + response = FetchFromCacheMiddleware(view_func).process_request(request) if response: return response # Since we don't have a response at this point, process the request. response = view_func(request, *args, **kwargs) # Cache the response. - response = UpdateCacheMiddleware().process_response(request, response) + response = UpdateCacheMiddleware(view_func).process_response( + request, response + ) return response return _wrapped_view_func From 28b7dd694480bcd71935aa2a67a643741f1347ed Mon Sep 17 00:00:00 2001 From: Vince Salvino Date: Wed, 21 Aug 2024 17:26:14 -0400 Subject: [PATCH 2/2] Version 2.5.1 and release notes --- docs/releases.rst | 6 ++++++ wagtailcache/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/releases.rst b/docs/releases.rst index 5fcc6ad..3c2faab 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -3,6 +3,12 @@ Release Notes ============= +2.5.1 +===== + +* Bug fix: Support Django 5.1 + + 2.5.0 ===== diff --git a/wagtailcache/__init__.py b/wagtailcache/__init__.py index ab41bfd..b023cb1 100644 --- a/wagtailcache/__init__.py +++ b/wagtailcache/__init__.py @@ -1,3 +1,3 @@ -release = ["2", "5", "0"] +release = ["2", "5", "1"] __version__ = "{0}.{1}.{2}".format(release[0], release[1], release[2]) __shortversion__ = "{0}.{1}".format(release[0], release[1])