Skip to content

ImportError: cannot import name 'get_show_toolbar' #938

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

Closed
timb07 opened this issue May 3, 2017 · 5 comments
Closed

ImportError: cannot import name 'get_show_toolbar' #938

timb07 opened this issue May 3, 2017 · 5 comments

Comments

@timb07
Copy link
Contributor

timb07 commented May 3, 2017

Since commit 68c4410, requests fail with ImportError: cannot import name 'get_show_toolbar'. (It was working fine with the previous commit.) Here's the relevant part of the traceback:

  File "/home/sid2/.local/lib/python3.5/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/home/sid2/.local/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 151, in __init__
    self.load_middleware()
  File "/home/sid2/.local/lib/python3.5/site-packages/django/core/handlers/base.py", line 56, in load_middleware
    mw_class = import_string(middleware_path)
  File "/home/sid2/.local/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/sid2/.local/lib/python3.5/site-packages/debug_toolbar/middleware.py", line 17, in <module>
    from debug_toolbar.toolbar import DebugToolbar
  File "/home/sid2/.local/lib/python3.5/site-packages/debug_toolbar/toolbar.py", line 135, in <module>
    urlpatterns = DebugToolbar.get_urls()
  File "/home/sid2/.local/lib/python3.5/site-packages/debug_toolbar/toolbar.py", line 121, in get_urls
    from . import views
  File "/home/sid2/.local/lib/python3.5/site-packages/debug_toolbar/views.py", line 7, in <module>
    from debug_toolbar.decorators import require_show_toolbar
  File "/home/sid2/.local/lib/python3.5/site-packages/debug_toolbar/decorators.py", line 5, in <module>
    from debug_toolbar.middleware import get_show_toolbar
ImportError: cannot import name 'get_show_toolbar'

I'm using Django 1.11, so I'm keen to use a recent commit that includes the fix for #910. (I'm using Python 3.5.2.) The test suite (run with tox -e py35-dj111) passes.

@matthiask
Copy link
Member

Hmm. Looks very much like a circular import error. Does it work if you move the get_show_toolbar import in decorators.py inside def inner?

@goblinJoel
Copy link

I can confirm we got this error at my company when we tried to use the development version of djdt on one of our dev servers, which uses uwsgi. (It was this error or a very similar one that also looked like a circular import error trying to import middleware from a view that was indirectly imported from middleware.) The error did not occur for us using manage.py runserver, but it did through uwsgi.

@timb07 We got around this temporarily by using the 1.7-tagged commit, with the #910 commit git cherry-pick'd on top of it. (Plus an additional commit of our own to ignore certain widget templates.) Not sure if that is a valid workaround for your case.

@timb07
Copy link
Contributor Author

timb07 commented May 3, 2017

@matthiask Yes, that fix works. Thanks for suggesting it.

@matthiask
Copy link
Member

matthiask commented May 4, 2017 via email

timb07 added a commit to timb07/django-debug-toolbar that referenced this issue May 4, 2017
@timb07
Copy link
Contributor Author

timb07 commented May 4, 2017

Done!

matthiask added a commit that referenced this issue May 4, 2017
Fix circular import issue; #938
khchine5 added a commit to khchine5/django-debug-toolbar that referenced this issue May 5, 2017
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

3 participants