stephenmcd / mezzanine

CMS framework for Django
http://mezzanine.jupo.org
BSD 2-Clause "Simplified" License
4.75k stars 1.64k forks source link

[BUG] __init__() missing 1 required positional argument: 'get_response' #2019

Closed DatCGI2net closed 2 years ago

DatCGI2net commented 2 years ago

Is there an existing issue for this?

Current Behavior

When setting cache for django, the issue is arosen.

Expected Behavior

It should be working when settings cache for django.

Steps To Reproduce

  1. Set cache in django settings like below
  2. Visit any pages, including admin

CACHES = { "default": { "BACKEND": "django.core.cache.backends.redis.RedisCache", "LOCATION": "redis://127.0.0.1:6379", } }

Environment

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/pages/richtextpage/2/change/

Django Version: 4.0.2
Python Version: 3.8.10
Installed Applications:
('mezzanine.boot',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.redirects',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.messages',
 'mezzanine.conf',
 'mezzanine.core',
 'mezzanine.generic',
 'mezzanine.pages',
 'mezzanine.blog',
 'mezzanine.forms',
 'mezzanine.galleries',
 'mezzanine.twitter',
 'mezzanine.accounts',
 'modeltranslation',
 'django_extensions',
 'theme',
 'payment',
 'paypal.standard.ipn',
 'tocheckout.tocheckout',
 'filebrowser_safe',
 'grappelli_safe',
 'django.contrib.admin',
 'django.contrib.staticfiles',
 'django_comments')
Installed Middleware:
('mezzanine.core.middleware.UpdateCacheMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'mezzanine.core.request.CurrentRequestMiddleware',
 'mezzanine.core.middleware.RedirectFallbackMiddleware',
 'mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware',
 'mezzanine.core.middleware.SitePermissionMiddleware',
 'mezzanine.pages.middleware.PageMiddleware',
 'mezzanine.core.middleware.FetchFromCacheMiddleware')

Traceback (most recent call last):
  File "/home/dat/.venv3/mezz3/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/dat/.venv3/mezz3/lib/python3.8/site-packages/django/utils/deprecation.py", line 125, in __call__
    response = self.process_request(request)
  File "/home/dat/.venv3/mezz3/lib/python3.8/site-packages/mezzanine/core/middleware.py", line 244, in process_request
    csrf_mw = CsrfViewMiddleware()

Exception Type: TypeError at /admin/pages/richtextpage/2/change/
Exception Value: __init__() missing 1 required positional argument: 'get_response'

Anything else?

No response

eht16 commented 2 years ago

I think the following patch solves the problem:

diff --git a/mezzanine/core/middleware.py b/mezzanine/core/middleware.py
index 224488ec..7efe1819 100755
--- a/mezzanine/core/middleware.py
+++ b/mezzanine/core/middleware.py
@@ -241,7 +241,7 @@ class FetchFromCacheMiddleware(MiddlewareMixin):
             # won't receieve one on their first request, with cache
             # middleware running.
             if csrf_middleware_installed():
-                csrf_mw = CsrfViewMiddleware()
+                csrf_mw = CsrfViewMiddleware(self.get_response)
                 csrf_mw.process_view(request, lambda x: None, None, None)
                 get_token(request)
             if response is None:

This makes the request fly fine through the middleware and the cached response is used. However, there might be a better or more proper solution to this. I'm not that familiar with Django's middlewares.

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 5.1.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: