Skip to content

Django integration breaks assertNumQueries #287

Open
@salomvary

Description

@salomvary

If I have sqlcommenter configured for a Django project, including when running tests with the default Django test runner, the assertNumQueries assertion fails with the following exception:

Traceback (most recent call last):
  File "test_something.py", line 4165, in test_some_feature
    with self.assertNumQueries(5):
         ~~~~~~~~~~~~~~~~~~~~~^^^
  File ".venv/lib/python3.13/site-packages/django/test/testcases.py", line 135, in __exit__
    "\n".join(
    ~~~~~~~~~^
        "%d. %s" % (i, query["sql"])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        for i, query in enumerate(self.captured_queries, start=1)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ),
    ^
  File ".venv/lib/python3.13/site-packages/django/test/testcases.py", line 136, in <genexpr>
    "%d. %s" % (i, query["sql"])
                   ~~~~~^^^^^^^
TypeError: string indices must be integers, not 'str'

Django version 5.1.4, Python 3.13.1, sqlcommenter 2.0.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions