Skip to content

Inconsistent behavior of DEBUG, debug_toolbar_urls() #2371

Description

@candletrick

I just spent an hour debugging why djdt was breaking a portion of our site after a deploy (notably the django admin). The 'djdt' namespace went missing.

It turns out it's because of inconsistent behavior in some functions around DEBUG.

Most of the functions ( notably in this case, debug_toolbar_urls() ), explicitly return nothing when DEBUG=False.

However, SHOW_TOOLBAR_CALLBACK allows the DJDT to appear in other contexts, notably in middleware.py, and then they mutually break each other.

One suggestion is shown below to make behavior consistent:

diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index aae69975..6f06e939 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -79,6 +79,9 @@ def show_toolbar_func_or_path() -> Callable:

     Cached to avoid importing multiple times.
     """
+    if not settings.DEBUG:
+        return False
+
     # If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
     # setup, resolve it to the corresponding callable.
     func_or_path = dt_settings.get_config()["SHOW_TOOLBAR_CALLBACK"]

Recommend changing this, or debug_toolbar_urls ... or the documentation ... This was confusing and tricky to track down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions