Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(t) Update Middlewares style #2662

Closed
FroggyFlox opened this issue Aug 20, 2023 · 2 comments · Fixed by #2663
Closed

(t) Update Middlewares style #2662

FroggyFlox opened this issue Aug 20, 2023 · 2 comments · Fixed by #2663
Assignees

Comments

@FroggyFlox
Copy link
Member

Thanks to @phillxnet, we now have a config to run with the Python's warning flag (#2655).
One of these warnings is relates to our use of Middlewares:

RemovedInDjango20Warning: Old-style middleware using settings.MIDDLEWARE_CLASSES is deprecated. Update your middleware and use settings.MIDDLEWARE instead.
  "instead.", RemovedInDjango20Warning

This most likely relates to the deprecation of MIDDLEWARE_CLASSES in Django 1.10:
https://docs.djangoproject.com/en/1.11/ref/settings/#middleware-classes

Deprecated since version 1.10: Old-style middleware that uses settings.MIDDLEWARE_CLASSES are deprecated. Adapt old, custom middleware and use the MIDDLEWARE setting.
This was the default setting used in Django 1.9 and earlier. Django 1.10 introduced a new style of middleware. If you have an older project using this setting you should update any middleware you’ve written yourself to the new style and then use the MIDDLEWARE setting.

Note that this was fully removed from Django 2.0:
https://docs.djangoproject.com/en/4.2/releases/2.0/#features-removed-in-2-0

Support for old-style middleware using settings.MIDDLEWARE_CLASSES is removed.

@FroggyFlox
Copy link
Member Author

We currently have the following:

MIDDLEWARE_CLASSES = (
# New in 1.8, 1.11 newly sets Content-Length header.
# 'django.middleware.common.CommonMiddleware',
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"storageadmin.middleware.ProdExceptionMiddleware",
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

We thus have:

  • several Django's included middlewares
  • 1 custom middleware

Note the following from Django's documentation:
https://docs.djangoproject.com/en/1.11/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware

Django provides django.utils.deprecation.MiddlewareMixin to ease creating middleware classes that are compatible with both MIDDLEWARE and the old MIDDLEWARE_CLASSES. All middleware classes included with Django are compatible with both settings.

We should thus be OK for the middlewares included in Django that we use.
We would need to adjust our custom middleware, however.

FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Aug 20, 2023
In Django 1.10, the old `MIDDLEWARE_CLASSES` style was deprecated and we
should now use `MIDDLEWARE` setting.

This commit includes this move and takes advantage of the new
MiddlewareMixin to help provide compatibility for our custom middleware.
@FroggyFlox FroggyFlox linked a pull request Aug 20, 2023 that will close this issue
phillxnet added a commit that referenced this issue Aug 22, 2023
@phillxnet
Copy link
Member

Closing as:
Fixed by #2663

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants