Repository: jazzband/django-debug-toolbar

Issue:
list values incorrectly adapted in SQL panel
I have a sql query containing `... WHERE id = ANY(%s)` and the param being a list, e.g. `[1, 2]`.

Adapted, the query looks like `id = ANY('{1,2}'::int2[]) `, but in the SQL panel, it shows up as `id = ANY('[1,2]')`. This is due to the parameters being quoted already before being passed to mogrify. Dropping the extra quoting step, the query shows up correctly in the SQL panel.

```
diff --git a/debug_toolbar/panels/sql/tracking.py b/debug_toolbar/panels/sql/tracking.py
index 0c53dc2c..bcff5905 100644
--- a/debug_toolbar/panels/sql/tracking.py
+++ b/debug_toolbar/panels/sql/tracking.py
@@ -115,15 +115,6 @@ class NormalCursorMixin(DjDTCursorWrapperMixin):
         else:
             return repr(element)
 
-    def _quote_params(self, params):
-        if not params:
-            return params
-        if isinstance(params, dict):
-            return {key: self._quote_expr(value) for key, value in params.items()}
-        if isinstance(params, tuple):
-            return tuple(self._quote_expr(p) for p in params)
-        return [self._quote_expr(p) for p in params]
-
     def _decode(self, param):
         if PostgresJson and isinstance(param, PostgresJson):
             # psycopg3
@@ -157,9 +148,7 @@ class NormalCursorMixin(DjDTCursorWrapperMixin):
         # process during the .last_executed_query() call.
         self.db._djdt_logger = None
         try:
-            return self.db.ops.last_executed_query(
-                self.cursor, sql, self._quote_params(params)
-            )
+            return self.db.ops.last_executed_query(self.cursor, sql, params)
         finally:
             self.db._djdt_logger = self.logger
 
```
Note that I've tested only with psycopg2/3, I don't know if other backends require the extra quoting.

[tracking.txt](https://github.com/jazzband/django-debug-toolbar/files/12611437/tracking.txt)



Discussion:
Patch adjusted, drop _quote_expr() as well:

[tracking.txt](https://github.com/jazzband/django-debug-toolbar/files/12617480/tracking.txt)

@tkoschnick can you create a PR please?

I'm pretty skeptical we can drop that quoting logic though. I'm curious how that change handles the test suite.

Resolving patch:
diff --git a/debug_toolbar/panels/sql/tracking.py b/debug_toolbar/panels/sql/tracking.py
--- a/debug_toolbar/panels/sql/tracking.py
+++ b/debug_toolbar/panels/sql/tracking.py
@@ -109,21 +109,6 @@ class NormalCursorMixin(DjDTCursorWrapperMixin):
     Wraps a cursor and logs queries.
     """
 
-    def _quote_expr(self, element):
-        if isinstance(element, str):
-            return "'%s'" % element.replace("'", "''")
-        else:
-            return repr(element)
-
-    def _quote_params(self, params):
-        if not params:
-            return params
-        if isinstance(params, dict):
-            return {key: self._quote_expr(value) for key, value in params.items()}
-        if isinstance(params, tuple):
-            return tuple(self._quote_expr(p) for p in params)
-        return [self._quote_expr(p) for p in params]
-
     def _decode(self, param):
         if PostgresJson and isinstance(param, PostgresJson):
             # psycopg3
@@ -157,9 +142,7 @@ def _last_executed_query(self, sql, params):
         # process during the .last_executed_query() call.
         self.db._djdt_logger = None
         try:
-            return self.db.ops.last_executed_query(
-                self.cursor, sql, self._quote_params(params)
-            )
+            return self.db.ops.last_executed_query(self.cursor, sql, params)
         finally:
             self.db._djdt_logger = self.logger
 


Test patch: