Skip to content

Commit

Permalink
Run DjDT only when DEBUG is set and not running tests rockstor#2939
Browse files Browse the repository at this point in the history
  • Loading branch information
FroggyFlox committed Dec 24, 2024
1 parent 3b9f8f2 commit 02f8ac0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
42 changes: 28 additions & 14 deletions src/rockstor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

# Django settings for Rockstor project.
import os
import sys

import distro
import keyring
from huey import SqliteHuey
Expand Down Expand Up @@ -162,7 +164,7 @@
]

MIDDLEWARE = (
"debug_toolbar.middleware.DebugToolbarMiddleware",
# "debug_toolbar.middleware.DebugToolbarMiddleware",
# New in 1.8, 1.11 newly sets Content-Length header.
# 'django.middleware.common.CommonMiddleware',
"django.contrib.sessions.middleware.SessionMiddleware",
Expand Down Expand Up @@ -201,7 +203,7 @@
"smart_manager",
"oauth2_provider",
"huey.contrib.djhuey",
"debug_toolbar",
# "debug_toolbar",
)

# https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-STORAGES
Expand Down Expand Up @@ -473,15 +475,27 @@
# For live updates (running system) we call distro.version() directly in code.
OS_DISTRO_VERSION = distro.version() # 3, 15.0 ,20181107

# Django Debug Toolbar-related settings and confrguration
INTERNAL_IPS = [
"127.0.0.1", # It seems requests always come from this when using DRF
]

# https://django-debug-toolbar.readthedocs.io/en/stable/configuration.html
DEBUG_TOOLBAR_CONFIG = {
# Update to the latest AJAX request
# Without this, we can only catch the initial request
# which is not helpful in most of our cases
"UPDATE_ON_FETCH": True
}
# DJANGO DEBUG TOOLBAR settings and configuration
# recommended NOT to use the toolbar when running tests
# so enable it only when NOT running tests or NOT DEBUG
TESTING = "test" in sys.argv
if (not TESTING) and DEBUG:
INSTALLED_APPS = [
*INSTALLED_APPS,
"debug_toolbar",
]
MIDDLEWARE = [
"debug_toolbar.middleware.DebugToolbarMiddleware",
*MIDDLEWARE,
]
INTERNAL_IPS = [
"127.0.0.1", # It seems requests always come from this when using DRF
]

# https://django-debug-toolbar.readthedocs.io/en/stable/configuration.html
DEBUG_TOOLBAR_CONFIG = {
# Update to the latest AJAX request
# Without this, we can only see the initial request in the toolbar panel
# Previous queries can still be seen and inspected in the "History" panel, though
"UPDATE_ON_FETCH": True
}
10 changes: 8 additions & 2 deletions src/rockstor/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from django.urls import include, re_path
from django.views.static import serve
from django.conf import settings
from debug_toolbar.toolbar import debug_toolbar_urls

from smart_manager.views import (
BaseServiceView,
Expand Down Expand Up @@ -150,4 +149,11 @@
re_path(
r"^api/update-subscriptions/", include("storageadmin.urls.update_subscription")
),
] + debug_toolbar_urls()
]

if (not settings.TESTING) and settings.DEBUG:
from debug_toolbar.toolbar import debug_toolbar_urls

urlpatterns = [
*urlpatterns,
] + debug_toolbar_urls()

0 comments on commit 02f8ac0

Please sign in to comment.