Skip to content

INTPYTHON-423 MQL panel for Django Debug Toolbar#29

Merged
aclark4life merged 36 commits intomongodb-labs:mainfrom
aclark4life:INTPYTHON-423
Apr 2, 2026
Merged

INTPYTHON-423 MQL panel for Django Debug Toolbar#29
aclark4life merged 36 commits intomongodb-labs:mainfrom
aclark4life:INTPYTHON-423

Conversation

@aclark4life
Copy link
Copy Markdown
Collaborator

@aclark4life aclark4life commented Feb 19, 2026

Summary of Changes

MQL Panel Enhancements

  • Added query explanation feature (mql_explain.html template)
  • Added query selection/inspection feature (mql_select.html template)
  • Implemented forms handling for query operations (forms.py)
  • Added views to handle AJAX requests for explain/select operations (views.py)
  • Rename tracking.py -> utils.py
  • Added utility functions for query formatting and processing (utils.py)

Testing

  • Added test suite based on the SQL panel tests from Django Debug Toolbar

Project Configuration

  • Updated CI workflows
  • Updated pyproject.toml dependencies and configuration
  • Updated .gitignore

Documentation

  • Updated README with usage instructions

Screenshots

Screenshot 2026-03-18 at 6 11 40 PM Screenshot 2026-03-18 at 6 38 23 PM Screenshot 2026-03-18 at 6 37 53 PM

@aclark4life aclark4life force-pushed the INTPYTHON-423 branch 30 times, most recently from c4d8429 to 7a10616 Compare February 20, 2026 17:27
Comment thread django_mongodb_extensions/templates/debug_toolbar/panels/mql.html
Comment thread tests/mql_panel/test_panel.py Outdated
Comment thread django_mongodb_extensions/mql_panel/utils.py Outdated
Comment thread django_mongodb_extensions/mql_panel/utils.py Outdated
Comment thread django_mongodb_extensions/mql_panel/panel.py Outdated
Comment thread django_mongodb_extensions/mql_panel/panel.py Outdated
Comment thread django_mongodb_extensions/mql_panel/panel.py Outdated
Comment thread django_mongodb_extensions/mql_panel/panel.py Outdated
Comment thread django_mongodb_extensions/templates/mql_panel/mql.html Outdated
Comment thread django_mongodb_extensions/mql_panel/utils.py Outdated
Comment on lines +16 to +17
{% if result %}
<h4>{% translate "Query Results" %}</h4>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove {% if %}, otherwise, we have a "Empty set" displayed without a header.

Comment thread django_mongodb_extensions/mql_panel/utils.py Outdated
Comment thread pyproject.toml Outdated
Comment thread django_mongodb_extensions/mql_panel/forms.py Outdated
Comment thread django_mongodb_extensions/mql_panel/utils.py
Comment thread django_mongodb_extensions/mql_panel/__init__.py
Comment thread django_mongodb_extensions/mql_panel/forms.py Outdated
Comment on lines 39 to 41
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since we have {% if result %} then the result will never be empty.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and found a query with "Empty set" so maybe there is some unexpected truthiness behavior somewhere in Django templates.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debug toolbar template looks like:

    {% if result %}
      <table>
        <thead>
          <tr>
            {% for h in headers %}
              <th>{{ h|upper }}</th>
            {% endfor %}
          </tr>
        </thead>
        <tbody>
          {% for row in result %}
            <tr>
              {% for column in row %}
                <td>{{ column|escape }}</td>
              {% endfor %}
            </tr>
          {% endfor %}
        </tbody>
      </table>
    {% else %}
      <p>{% translate "Empty set" %}</p>
    {% endif %}

I think what happened is that in a past review, I suggested adding {% empty %}, not seeing {% if result %}.

Comment thread tests/mql_panel/test_panel.py Outdated
Comment on lines -108 to -112
def test_title(self):
mql_call()
response = self.panel.process_request(self.request)
self.panel.generate_stats(self.request, response)
self.assertEqual(self.panel.title, "MQL queries from 1 connection")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you inadvertently delete the test_title (or at least the assertion for it)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll put it back and account for multiple connections.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we don't need to test multiple connections?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well sure, tests for multiple connections would be nice but I'd prioritize tests for views and templates as that accounts for many more untested lines.

Comment thread django_mongodb_extensions/mql_panel/forms.py Outdated
Comment thread django_mongodb_extensions/templates/mql_panel/mql_query.html Outdated
Comment thread django_mongodb_extensions/mql_panel/forms.py Outdated
Comment thread django_mongodb_extensions/mql_panel/panel.py Outdated
Comment thread django_mongodb_extensions/mql_panel/forms.py Outdated
Comment thread django_mongodb_extensions/mql_panel/forms.py Outdated
Comment thread tests/mql_panel/test_forms.py Outdated
Comment thread django_mongodb_extensions/mql_panel/utils.py Outdated
Comment thread django_mongodb_extensions/mql_panel/forms.py Outdated
<tr>
<th>{{ sub.key }}</th>
<td>
{% if sub.type == "dict" %}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the same code is repeated below, so it could be an {% include %}.

Does it support arbitrary layers of nested documents? It doesn't look like but maybe there is some flattening happening in the form (didn't take time to understand large blocks of uncommented code).

I'm getting uncomfortable with the large amount of logic in this template, but I won't insist on another approach.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it support arbitrary layers of nested documents? It doesn't look like but maybe there is some flattening happening in the form (didn't take time to understand large blocks of uncommented code).

Fixed in 924a954

Comment thread tests/mql_panel/test_forms.py Outdated
Comment thread tests/mql_panel/test_forms.py Outdated
Comment thread tests/mql_panel/test_forms.py Outdated
Comment thread tests/mql_panel/test_forms.py Outdated
Comment thread tests/mql_panel/test_forms.py Outdated
dependabot bot and others added 2 commits April 1, 2026 20:36
mongodb-labs#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants