Skip to content

Commit b98c4ce

Browse files
aclark4lifetimgrahamclaudedependabot[bot]
authored
INTPYTHON-423 MQL panel for Django Debug Toolbar (#29)
* Implement MQL panel for Django Debug Toolbar * Address review feedback - Just use validation error - Remove type hints - Document Exception - Use debug_toolbar's get_signed_data - Fix docstrings in tests - s/sql/mql/g - Narrow exception * Delete .coverage * Address review feedback (🤖 assisted) * Add tests based on sql panel tests (🤖 assisted) * Jib review fixes * readme edits * Update gitignore * Address review feedback * Remove find * Fix convert_documents_to_table and add test * Address review feedback * Address review feedback Co-Authored-By: Claude Code <noreply@anthropic.com> * Add template_info support to MQL panel Co-Authored-By: Claude Code <noreply@anthropic.com> * Address review feedback * Move template_info above stacktrace * More verbose test run output * Add test coverage harness * Rename select -> aggregate * Fix package version resolution for coverage * Move utils tests from test_panel -> test_utils * Move forms tests from test_utils -> tests_forms * Add QueryPartsTests * Rename mql select -> mql query * Address review feedback * Move MQL panel tests to tests/debug_toolbar/ * Rename debug_toolbar.panels.mql/* -> mql_panel/* * Update readme * Refactor mql form clean() method * Address review feedback * Format mql_query and fix dhtml pre-commit hook * Alpha-sort class methods * Address review feedback * Refactor tests * Bump zizmorcore/zizmor-action from 0.5.0 to 0.5.2 in the actions group (#33) Bumps the actions group with 1 update: [zizmorcore/zizmor-action](https://github.com/zizmorcore/zizmor-action). Updates `zizmorcore/zizmor-action` from 0.5.0 to 0.5.2 - [Release notes](https://github.com/zizmorcore/zizmor-action/releases) - [Commits](zizmorcore/zizmor-action@0dce257...71321a2) --- updated-dependencies: - dependency-name: zizmorcore/zizmor-action dependency-version: 0.5.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: actions ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Address review feedback --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Tim Graham <timograham@gmail.com> Co-authored-by: Claude Code <noreply@anthropic.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 8a45109 commit b98c4ce

File tree

29 files changed

+1317
-218
lines changed

29 files changed

+1317
-218
lines changed

.github/workflows/test-python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
with:
8787
mongodb-version: ${{ env.MIN_MONGODB }}
8888
mongodb-replica-set: test-rs
89-
- name: Run unit tests with minimum dependency versions
89+
- name: Run unit tests with minimum Python/MongoDB versions
9090
run: |
91-
uv sync --python=${MIN_PYTHON} --resolution=lowest-direct
91+
uv sync --python=${MIN_PYTHON} --resolution=highest
9292
just test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
__pycache__
2+
uv.lock
3+
.coverage

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ repos:
2020
hooks:
2121
- id: djhtml
2222
entry: djhtml --tabwidth 2
23-
files: django_mongodb_extensions/templates/debug_toolbar/panels/mql.html

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,79 @@
11
# django-mongodb-extensions
22

33
Extensions for Django MongoDB Backend
4+
5+
## Installation
6+
7+
```bash
8+
pip install django-mongodb-extensions
9+
```
10+
11+
## Extensions
12+
13+
### MQL Panel
14+
15+
This panel for
16+
[Django Debug Toolbar](https://github.com/jazzband/django-debug-toolbar)
17+
provides insights into MongoDB queries executed during a request
18+
similar to how the SQL panel works for relational databases.
19+
20+
**Features:**
21+
22+
- View all MongoDB queries (MQL) executed during a request
23+
- See query execution time and identify slow queries
24+
- Re-execute read operations (aggregate) directly from the toolbar
25+
- Explain query execution plans
26+
- Color-coded query grouping for easy identification
27+
- Detailed query statistics and performance metrics
28+
29+
#### Configure the MQL Panel
30+
31+
First, install and configure Django Debug Toolbar by following their
32+
[installation instructions](https://django-debug-toolbar.readthedocs.io/en/latest/installation.html).
33+
34+
1. **Add to `INSTALLED_APPS`** in your Django settings:
35+
36+
```python
37+
INSTALLED_APPS = [
38+
# ...
39+
"django_mongodb_extensions",
40+
# ...
41+
]
42+
```
43+
44+
2. **Add the MQL Panel** to your debug toolbar configuration:
45+
46+
```python
47+
DEBUG_TOOLBAR_PANELS = [
48+
"debug_toolbar.panels.history.HistoryPanel",
49+
"debug_toolbar.panels.versions.VersionsPanel",
50+
"debug_toolbar.panels.timer.TimerPanel",
51+
"debug_toolbar.panels.settings.SettingsPanel",
52+
"debug_toolbar.panels.headers.HeadersPanel",
53+
"debug_toolbar.panels.request.RequestPanel",
54+
# Add this:
55+
"django_mongodb_extensions.mql_panel.MQLPanel",
56+
"debug_toolbar.panels.templates.TemplatesPanel",
57+
"debug_toolbar.panels.staticfiles.StaticFilesPanel",
58+
"debug_toolbar.panels.cache.CachePanel",
59+
"debug_toolbar.panels.signals.SignalsPanel",
60+
"debug_toolbar.panels.redirects.RedirectsPanel",
61+
"debug_toolbar.panels.profiling.ProfilingPanel",
62+
]
63+
```
64+
65+
3. **Optional:** Configure settings.
66+
67+
```python
68+
# Maximum number of documents to return when re-executing select
69+
# queries (default is 100).
70+
DJDT_MQL_MAX_QUERY_RESULTS = 25
71+
72+
# Queries slower than this threshold (in milliseconds) are highlighted
73+
# in the debug toolbar (default is 500 ms).
74+
DJDT_MQL_WARNING_THRESHOLD = 1000
75+
```
76+
77+
## License
78+
79+
See [LICENSE](LICENSE) file for details.

django_mongodb_extensions/debug_toolbar/panels/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

django_mongodb_extensions/debug_toolbar/panels/mql/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

django_mongodb_extensions/debug_toolbar/panels/mql/panel.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

django_mongodb_extensions/debug_toolbar/panels/mql/tracking.py

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django_mongodb_extensions.mql_panel.panel import MQLPanel
2+
3+
__all__ = [MQLPanel.panel_id]

0 commit comments

Comments
 (0)