coderedcorp / wagtail-cache

A simple page cache for Wagtail based on the Django cache middleware.
Other
87 stars 29 forks source link

Cache middleware breaks in Django 5.1 #74

Closed jlchilders11 closed 3 months ago

jlchilders11 commented 3 months ago

image

AnthonyUphof-zacailab commented 3 months ago

Experiencing similar issue,
python 3.11 using https://github.com/coderedcorp/coderedcms.git@v4.0.1

app-1  |   File "/app/myapp/myapp/asgi.py", line 25, in <module>
app-1  |     django_asgi_app = get_asgi_application()
app-1  |                       ^^^^^^^^^^^^^^^^^^^^^^
app-1  |   File "/usr/local/lib/python3.11/site-packages/django/core/asgi.py", line 13, in get_asgi_application
app-1  |     return ASGIHandler()
app-1  |            ^^^^^^^^^^^^^
app-1  |   File "/usr/local/lib/python3.11/site-packages/django/core/handlers/asgi.py", line 148, in __init__
app-1  |     self.load_middleware(is_async=True)
app-1  |   File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 61, in load_middleware
app-1  |     mw_instance = middleware(adapted_handler)
app-1  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
app-1  |   File "/usr/local/lib/python3.11/site-packages/wagtailcache/cache.py", line 189, in __init__
app-1  |     self._async_check()
app-1  |     ^^^^^^^^^^^^^^^^^
app-1  | AttributeError: 'FetchFromCacheMiddleware' object has no attribute '_async_check'
AnthonyUphof-zacailab commented 3 months ago

Appears the _async_check() was removed after Django 5.0 see https://github.com/django/django/commit/e2922b0d5f18169d1d0115a6db5d2ed8c42d0692.

Also note that django/utils/deprecation.py has deprecation warnings now set to 6.0 and 6.1 but unclear what this deprecation.py is really for. A confusing but enlightening overview at https://stackoverflow.com/a/52913499/6940121.

Appears the following works as a simple fix ?


# and then ammend the __init__ to call super()
class FetchFromCacheMiddleware(MiddlewareMixin):
    def __init__(self, get_response=None):
        super().__init__(get_response)
       .............. # rest of __init__
class UpdateCacheMiddleware(MiddlewareMixinFixed):
    def __init__(self, get_response=None):
        super().__init__(get_response)
       .............. # rest of __init__
vsalvino commented 3 months ago

@AnthonyUphof-zacailab thanks for the link. The code structure of wagtail-cache originally a copy of the Django cache middleware, then grew into its own beast over time. I'd be open to refactoring it to the "correct" way.

What I'm currently trying to figure out is can we have compatibility with both Django 4.2-5.0, and 5.1 at the same time? Or do we need to cut a separate release for those?