streeter / django-db-readonly

Force an entire site to become readonly. In a sort of hackish way.
MIT License
108 stars 21 forks source link

DatabaseReadOnlyMiddleware not compatible with new Django new-style MIDDLEWARE #14

Closed scotartt closed 6 years ago

scotartt commented 7 years ago

The following settings directive

MIDDLEWARE_CLASSES = (
    # ...
    'readonly.middleware.DatabaseReadOnlyMiddleware',
    # ...
)

Doesn't work for the new Django 1.10 MIDDLEWARE new-style setup.

MIDDLEWARE = [
    # ...
    'readonly.middleware.DatabaseReadOnlyMiddleware',
]

See https://docs.djangoproject.com/en/1.10/releases/1.10/#new-style-middleware

You end up with an error like this:

  File "/.../appname/wsgi.py", line 14, in <module>
    application = get_wsgi_application()
  File "/.../pythonenv/python3.5/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/.../pythonenv/python3.5/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/.../pythonenv/python3.5/lib/python3.5/site-packages/django/core/handlers/base.py", line 82, in load_middleware
    mw_instance = middleware(handler)
TypeError: object() takes no parameters
avelis commented 6 years ago

Is there a workaround for this. Or a PR in the works?

avelis commented 6 years ago

@streeter I created a quick PR. It's bare bones though. Has Django version checks, but it's a start.