Skip to content

Commit 9bc1889

Browse files
committed
Hide the toolbar's models when the database store isn't used.
1 parent 2e9cf79 commit 9bc1889

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

debug_toolbar/apps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def ready(self):
2626
cls.ready()
2727
_manage_migrations_visibility(self.name)
2828

29+
def import_models(self):
30+
dt_config = dt_settings.get_config()
31+
if dt_config["TOOLBAR_STORE_CLASS"] == "debug_toolbar.store.DatabaseStore":
32+
return super().import_models()
33+
# Not using the database store, don't import the models
34+
self.models = {}
35+
2936

3037
def _manage_migrations_visibility(app_name):
3138
"""

docs/changes.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ Pending
1616
* Upgraded CI ``postgis`` version to 17-3.5.
1717
* Added how to generate the documentation locally to the contributing
1818
documentation.
19-
* Hide the toolbar's migrations unless the database store is being used. This
20-
may change in the future.
19+
* Hide the toolbar's migrations unless ``debug_toolbar.store.DatabaseStore``
20+
is being used. This may change in the future.
21+
* Hide ``debug_toolbar.HistoryEntry`` as a model unless
22+
``debug_toolbar.store.DatabaseStore`` is being used. This may change in the
23+
future.
2124

2225
6.0.0 (2025-07-22)
2326
------------------

tests/test_apps.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from unittest.mock import patch
22

3+
from django.apps import apps
34
from django.test import SimpleTestCase, override_settings
45

56
from debug_toolbar.apps import _manage_migrations_visibility
@@ -25,3 +26,22 @@ def test_migrations_are_hidden(self, mocked_migration_modules):
2526
mocked_migration_modules.setdefault.assert_called_once_with(
2627
"debug_toolbar", None
2728
)
29+
30+
@override_settings(
31+
DEBUG_TOOLBAR_CONFIG={
32+
"TOOLBAR_STORE_CLASS": "debug_toolbar.store.DatabaseStore"
33+
}
34+
)
35+
def test_models_are_visible(self):
36+
app_config = apps.get_app_config("debug_toolbar")
37+
app_config.import_models()
38+
apps.get_model("debug_toolbar", "HistoryEntry")
39+
40+
@override_settings(
41+
DEBUG_TOOLBAR_CONFIG={"TOOLBAR_STORE_CLASS": "debug_toolbar.store.MemoryStore"}
42+
)
43+
def test_models_are_hidden(self):
44+
app_config = apps.get_app_config("debug_toolbar")
45+
app_config.import_models()
46+
with self.assertRaises(LookupError):
47+
apps.get_model("debug_toolbar", "HistoryEntry")

0 commit comments

Comments
 (0)