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

Error after update to 4.4.1 (debug_toolbar.E001) The Django Debug Toolbar can't be used with tests #1920

Closed
MarcoGlauser opened this issue May 27, 2024 · 5 comments · Fixed by #1921 or #1925

Comments

@MarcoGlauser
Copy link

After upgrading to 4.4.1 we got an error when trying to run our tests, despite DEBUG being False:

(debug_toolbar.E001) The Django Debug Toolbar can't be used with tests
	HINT: Django changes the DEBUG setting to False when running tests. By default the Django Debug Toolbar is installed because DEBUG is set to True. For most cases, you need to avoid installing the toolbar when running tests. If you feel this check is in error, you can set `DEBUG_TOOLBAR_CONFIG['IS_RUNNING_TESTS'] = False` to bypass this check.

It took us a while to figure out what went wrong. It turns out the default installation method, recommended in the docs, doesn't work with the the changes from 4.4.0 (even if DEBUG is False, which should deactivate Debug Toolbar)

After some back and forth we figured out that the example directory configuration was the only way to run our tests:

ENABLE_DEBUG_TOOLBAR = DEBUG and "test" not in sys.argv
if ENABLE_DEBUG_TOOLBAR:
    INSTALLED_APPS += [
        "debug_toolbar",
    ]
    MIDDLEWARE += [
        "debug_toolbar.middleware.DebugToolbarMiddleware",
    ]

The default installation docs are haven't changed for the 4.4.0 release and the example app is different than the recommended installation in the docs. Is this a missed docs update or an unintended breaking change?

@matthiask
Copy link
Member

Thank you. Yes, we should have also changed the installation instructions, sorry for that. You discovered the best way to do it.

matthiask added a commit to matthiask/django-debug-toolbar that referenced this issue May 27, 2024
Fixes django-commons#1920.

I thought about including the relevant documentation in the earlier
steps, but I'd have to explain DEBUG, INTERNAL_IPS and TESTING all at
once instead of introducing everything step by step. So even though it
may be annoying to go back and modify code the user just added it still
reads better to me, especially since it only applies to users running
tests in their project. (I would hope a lot of them do, but still.)
matthiask added a commit to matthiask/django-debug-toolbar that referenced this issue May 27, 2024
Fixes django-commons#1920.

I thought about including the relevant documentation in the earlier
steps, but I'd have to explain DEBUG, INTERNAL_IPS and TESTING all at
once instead of introducing everything step by step. So even though it
may be annoying to go back and modify code the user just added it still
reads better to me, especially since it only applies to users running
tests in their project. (I would hope a lot of them do, but still.)
matthiask added a commit to matthiask/django-debug-toolbar that referenced this issue May 27, 2024
Fixes django-commons#1920.

I thought about including the relevant documentation in the earlier
steps, but I'd have to explain DEBUG, INTERNAL_IPS and TESTING all at
once instead of introducing everything step by step. So even though it
may be annoying to go back and modify code the user just added it still
reads better to me, especially since it only applies to users running
tests in their project. (I would hope a lot of them do, but still.)
@tim-schilling
Copy link
Member

tim-schilling commented May 27, 2024

It took us a while to figure out what went wrong. It turns out the default installation method, recommended in the docs, doesn't work with the the changes from 4.4.0 (even if DEBUG is False, which should deactivate Debug Toolbar)

To be clear, having DEBUG = False doesn't prevent the toolbar from some of the panels from setting up instrumentation. The only way to avoid any instrumentation is to not add the toolbar to INSTALLED_APPS.

@tim-schilling
Copy link
Member

@MarcoGlauser do you remember what you originally had for the DEBUG_TOOLBAR_CONFIG setting? Were you customizing SHOW_TOOLBAR_CALLBACK?

@MarcoGlauser
Copy link
Author

Thank you all for responding so quickly to this :)
We did not set any config settings, just the standard install as it's in the docs.

While trying to figure out what changed yesterday, I created a reproduction:
https://github.com/MarcoGlauser/debug-toolbar-repro/blob/main/mysite/mysite/settings.py

@tim-schilling
Copy link
Member

Ah, thank you!

azegas added a commit to azegas/django_starter that referenced this issue May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants