nitely / django-djconfig

:gear: Dynamic configuration made easy
http://django-djconfig.readthedocs.org
MIT License
32 stars 5 forks source link

MIDDLEWARE_CLASSES setting is deprecated in Django 1.10 #23

Closed cryptogun closed 7 years ago

cryptogun commented 7 years ago

django-djconfig version: 0.5.1 I merged spirit.settings into my settings. When doing manage.py makemigrations I got the following warning:

The MIDDLEWARE_CLASSES setting is deprecated in Django 1.10 and the MIDDLEWARE setting takes precedence. Since you've set MIDDLEWARE, the value of MIDDLEWARE_CLASSES is ignored.

And then I changed all MIDDLEWARE_CLASSES to MIDDLEWARE I got the following error:

  File "/home/i/Desktop/env/lib/python3.5/site-packages/djconfig/conf.py", line 75, in _check_backend
    "djconfig.middleware.DjConfigMiddleware is required "
ValueError: djconfig.middleware.DjConfigMiddleware is required but it was not found in MIDDLEWARE_CLASSES

Now my solution is keep both MIDDLEWARE_CLASSES and MIDDLEWARE, and only one item in MIDDLEWARE_CLASSES.

MIDDLEWARE_CLASSES = [
    'djconfig.middleware.DjConfigMiddleware',
]

Edit: Now I can't keep both MIDDLEWARE_CLASSES and MIDDLEWARE otherwise TypeError: object() takes no parameters would occur (see here), and have to use MIDDLEWARE_CLASSES only.

nitely commented 7 years ago

I was not aware of the new middleware. I'll fix it. MIDDLEWARE_CLASSES will work until Django 2.0, though.

cryptogun commented 7 years ago

Great. Thanks.

cryptogun commented 7 years ago

Well, I reinstalled spirit and djconfig and set MIDDLEWARE only. And found that you forgot to modify this line. Traceback:

  File "/home/i/Desktop/env/lib/python3.5/site-packages/spirit/admin/apps.py", line 15, in ready
    self.register_config()
  File "/home/i/Desktop/env/lib/python3.5/site-packages/spirit/admin/apps.py", line 21, in register_config
    djconfig.register(BasicConfigForm)
  File "/home/i/Desktop/env/lib/python3.5/site-packages/djconfig/conf.py", line 53, in _register
    self._check_backend()
  File "/home/i/Desktop/env/lib/python3.5/site-packages/djconfig/conf.py", line 75, in _check_backend
    "djconfig.middleware.DjConfigMiddleware is required "
ValueError: djconfig.middleware.DjConfigMiddleware is required but it was not found in MIDDLEWARE_CLASSES
nitely commented 7 years ago

Dang. I was too lazy to test it, just fixed the fix (and added proper unit tests).

cryptogun commented 7 years ago

Tested OK. Thanks.