Description
With django debug toolbar 2.2 (since 2.0) I see a lot of duplicated queries.
When turning on logging for sql queries, I see them only once, and when debugging, those queries are clearly executed only once.
I found out that this only happens when using chunked cursors, because debug toolbar wraps the cursor twice, leading to logging it twice and wrongly marking it as duplicated.
Please see this line:
https://github.com/jazzband/django-debug-toolbar/blob/2.2/debug_toolbar/panels/sql/tracking.py#L58
It wraps the cursor returned from connection._djdt_chunked_cursor
.
For databases without a special implementation for chunked cursors (e.g. mysql), that method actually just runs connection.cursor
:
https://github.com/django/django/blob/2.2.10/django/db/backends/base/base.py#L572
Which in turn wraps the cursor a second time:
https://github.com/jazzband/django-debug-toolbar/blob/2.2/debug_toolbar/panels/sql/tracking.py#L53