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

Middleware Errors on New Project #827

Closed
chromakey opened this issue Sep 29, 2016 · 16 comments
Closed

Middleware Errors on New Project #827

chromakey opened this issue Sep 29, 2016 · 16 comments

Comments

@chromakey
Copy link

chromakey commented Sep 29, 2016

Generated a brand new project this morning using master. Installed requirements and ran the initial migrations. No changes were made to the generated code. Wondering if this error might be related to this PR which was merged about 10 hours ago: #793.

Thank you everyone for your work on this great project.

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fd59fc8f510>
Traceback (most recent call last):
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
    handler = self.get_handler(*args, **options)
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super(Command, self).get_handler(*args, **options)
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/home/bill/.virtualenvs/xxxy/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    return import_string(app_path)
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/bill/projects/xxx/config/wsgi.py", line 30, in <module>
    application = get_wsgi_application()
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
    self.load_middleware()
  File "/home/bill/.virtualenvs/xxx/lib/python3.5/site-packages/django/core/handlers/base.py", line 82, in load_middleware
    mw_instance = middleware(handler)
TypeError: __init__() takes 1 positional argument but 2 were given

Project Settings:

~/projects$ cookiecutter https://github.com/pydanny/cookiecutter-django
You've cloned /home/bill/.cookiecutters/cookiecutter-django before. Is it okay to delete and re-clone it? 
[yes]: yes
Cloning into 'cookiecutter-django'...
remote: Counting objects: 8020, done.
remote: Total 8020 (delta 0), reused 0 (delta 0), pack-reused 8019
Receiving objects: 100% (8020/8020), 2.86 MiB | 0 bytes/s, done.
Resolving deltas: 100% (5187/5187), done.
Checking connectivity... done.
project_name [Project Name]: xxx
project_slug [xxx]: xxx
author_name [Daniel Roy Greenfeld]: xxx
email [you@example.com]: xxx
description [A short description of the project.]: xxx
domain_name [example.com]: xxx.com
version [0.1.0]: 
timezone [UTC]: 
use_whitenoise [y]: n
use_celery [n]: n
use_mailhog [n]: y
use_sentry_for_error_reporting [y]: n
use_opbeat [n]: y
use_pycharm [n]: y
windows [n]: n
use_python3 [y]: y
use_docker [y]: n
use_heroku [n]: n
use_elasticbeanstalk_experimental [n]: n
use_compressor [n]: n
Select postgresql_version:
1 - 9.5
2 - 9.4
3 - 9.3
4 - 9.2
Choose from 1, 2, 3, 4 [1]: 1
Select js_task_runner: 3
1 - Gulp
2 - Grunt
3 - None
Choose from 1, 2, 3 [1]: 3
use_lets_encrypt [n]: n
Select open_source_license:
1 - MIT
2 - BSD
3 - GPLv3
4 - Apache Software License 2.0
5 - Not open source
Choose from 1, 2, 3, 4, 5 [1]: 5


@chromakey
Copy link
Author

The requirements file on the master branch currently lists Django==1.10.1 so I think it shouldn't be a 1.9.x issue here?

@luzfcb
Copy link
Collaborator

luzfcb commented Sep 29, 2016

@chromakey is a new project? I'm trying to reproduce the error based on your cookiecutter configs.

to the error described occurs, which command you executed?

@chromakey
Copy link
Author

Brand new project. Created it running this:

cookiecutter https://github.com/pydanny/cookiecutter-django

After installing the requirements and doing the migration, I ran the project with this

python manage.py runserver

PostgreSQL database if it matters.

@ssteinerx
Copy link
Contributor

@chromakey Are you in a virtualenv and could you run:

pip list

@chromakey
Copy link
Author

chromakey commented Sep 29, 2016

Ubuntu 16.04 with Python 3.5.2 if either matters.

alabaster (0.7.9)
awesome-slugify (1.6.5)
Babel (2.3.4)
coverage (4.2)
decorator (4.0.10)
defusedxml (0.4.1)
Django (1.10.1)
django-allauth (0.27.0)
django-braces (1.9.0)
django-coverage-plugin (1.3.1)
django-crispy-forms (1.6.0)
django-debug-toolbar (1.5)
django-environ (0.4.0)
django-extensions (1.7.4)
django-model-utils (2.6)
django-redis (4.5.0)
django-test-plus (1.0.15)
docutils (0.12)
factory-boy (2.7.0)
fake-factory (0.7.2)
imagesize (0.7.1)
ipdb (0.10.1)
ipython (5.1.0)
ipython-genutils (0.1.0)
Jinja2 (2.8)
MarkupSafe (0.23)
oauthlib (2.0.0)
pexpect (4.2.1)
pickleshare (0.7.4)
Pillow (3.3.1)
pip (8.1.2)
pkg-resources (0.0.0)
prompt-toolkit (1.0.7)
psycopg2 (2.6.2)
ptyprocess (0.5.1)
py (1.4.31)
Pygments (2.1.3)
pytest (3.0.2)
pytest-django (3.0.0)
pytest-sugar (0.7.1)
python-dateutil (2.5.3)
python3-openid (3.0.10)
pytz (2016.6.1)
redis (2.10.5)
regex (2016.9.22)
requests (2.11.1)
requests-oauthlib (0.7.0)
setuptools (28.0.0)
simplegeneric (0.8.1)
six (1.10.0)
snowballstemmer (1.2.1)
Sphinx (1.4.6)
sqlparse (0.2.1)
termcolor (1.1.0)
traitlets (4.3.1)
Unidecode (0.4.19)
wcwidth (0.1.7)
Werkzeug (0.11.11)
wheel (0.29.0)

@jayfk
Copy link
Collaborator

jayfk commented Sep 29, 2016

That looks right.

@ssteinerx
Copy link
Contributor

ssteinerx commented Sep 29, 2016

I got this on migration (running on py2.7, but said "use python3: y" as @chromakey did.

I know that's wrong, but it happened...

System check identified some issues:

WARNINGS:
?: (1_10.W001) 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, I got the same load_middleware exception as @chromakey did.

@chromakey
Copy link
Author

I received that warning as well @ssteinerx but I didn't include it in the traceback.

@ssteinerx
Copy link
Contributor

ssteinerx commented Sep 29, 2016

Is there both a MIDDLEWARE and MIDDLEWARE_CLASSES being pulled in?

That doesn't explain the exception (I don't think?), but we shouldn't have both in any case as MIDDLEWARE_CLASSES will be ignored.

@luzfcb
Copy link
Collaborator

luzfcb commented Sep 29, 2016

@chromakey @jayfk I can confirm the error.

@ssteinerx
Copy link
Contributor

There does not seem to be an instance of MIDDLEWARE_CLASSES in the generated app:

find . -name "*.py" -exec grep "MIDDLEWARE" {} \; -print
# MIDDLEWARE CONFIGURATION
MIDDLEWARE = (
./config/settings/common.py
MIDDLEWARE += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
./config/settings/local.py
MIDDLEWARE = (
) + MIDDLEWARE
./config/settings/production.py

@chromakey
Copy link
Author

I think I found the issue. It's with django-debug-toolbar. Commenting it out in the configuration seems to get everything to work. I found this recently merged PR:

jazzband/django-debug-toolbar#879

It looks like pypi hasn't been updated yet to reflect the merged changes.

@ssteinerx
Copy link
Contributor

#810

@luzfcb
Copy link
Collaborator

luzfcb commented Sep 29, 2016

@chromakey please test the branch fix-debug-toolbar-issue-827

git clone -b fix-debug-toolbar-issue-827  --single-branch https://github.com/pydanny/cookiecutter-django.git

cookiecutter cookiecutter-django/

after that, create a new clean virtualenv and load, and inside the created project, run:

pip install -r requirements/local.txt -r requirements/test.txt -r requirements/production.txt
python manage.py migrate
python manage.py runserver

@chromakey
Copy link
Author

@luzfcb using your instructions above I was able to get it to run successfully with no additional changes.

@luzfcb
Copy link
Collaborator

luzfcb commented Sep 29, 2016

fixed in cbb132c

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

No branches or pull requests

4 participants