-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate queries not correctly detected #1239
Comments
Do you have a test case that we can reproduce this with? |
I am seeing the same, not sure how I can easily create a test case as I am seeing this in a project with a It seems to only be happening for queries that involve django-filter to render dropdown/multiselect html widgets and consistenly show 2 queries, of which the first 1 is very fast: Don't know if a stacktrace helps, but both queries have the exact same stacktrace:
|
I just hit this with SQLite. I'll try and follow-up with a sample project next week, but it's just simple model. Commenting out the overriding of the I'm guessing a check to see if the returned cursor is already wrapped might be sufficient. 🤔 |
I encountered the same problem while trying to investigate a performance issue. This is rather confusing because one sees the same query and the same stack trace but different times. Preventing the wrapping of chunked_cursor resolved the issue. I made a PR #1475 but not sure if this is acceptable like that. |
@saemideluxe — Glad it was helpful. Thanks 😊 |
#1478 offers an attempt to add test coverage for this issue (including both chunked and non-chunked cursors, to try to avoid any future regressions). |
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
The text was updated successfully, but these errors were encountered: