Skip to content

Commit 3f6ab47

Browse files
committed
Remove duplicate query logging that breaks Django's assertNumQueries
The SqlCommenter _QueryWrapper manually appends the SQL string to queries_log when a CursorDebugWrapper is active. However, CursorDebugWrapper.debug_sql already logs the query as a dict with "sql" and "time" keys. This causes two problems: 1. Queries are double-counted in queries_log 2. The raw string entries cause a TypeError in Django's assertNumQueries, which expects dict entries with a "sql" key Remove the manual append and let Django handle query logging.
1 parent 195bcdb commit 3f6ab47

1 file changed

Lines changed: 0 additions & 5 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware

instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/sqlcommenter_middleware.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# pylint: disable=no-name-in-module
1919
from django import conf, get_version
2020
from django.db import connections
21-
from django.db.backends.utils import CursorDebugWrapper
2221

2322
from opentelemetry.instrumentation.sqlcommenter_utils import _add_sql_comment
2423
from opentelemetry.instrumentation.utils import _get_opentelemetry_values
@@ -122,8 +121,4 @@ def __call__(self, execute: Type[T], sql, params, many, context) -> T:
122121
# * https://github.com/basecamp/marginalia/issues/61
123122
# * https://github.com/basecamp/marginalia/pull/80
124123

125-
# Add the query to the query log if debugging.
126-
if isinstance(context["cursor"], CursorDebugWrapper):
127-
context["connection"].queries_log.append(sql)
128-
129124
return execute(sql, params, many, context)

0 commit comments

Comments
 (0)