django-debug-toolbar
django-debug-toolbar copied to clipboard
SQL section of toolbar assumes database supports explain
The SQL section of the toolbar assumes that the database supports explain (probably MySQL is being assumed) and attempts to run the SQL query with explain which results in a 500 error. The toolbar should check the driver before making any such assumptions.
Postgres also suppors EXPLAIN. Which database are you referring to?
SQL Server but I'm sure there are other examples. For instance Oracle might not have that capability and a lot more than MySQL and Postgres are supported by django through ODBC. In fact I'm using django_pyodbc to connect to SQL Server.
I'm testing django-debug-toolbar 2.0a1 and ran into this issue while using an Oracle backend cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number
djdt tries to run : QUERY = 'EXPLAIN SELECT.... while Oracle expects something like 'EXPLAIN PLAN FOR SELECT...' to get the execution plan Note: I'm far from an oracle expert.
Django has some support for .explain() since 2017 (https://github.com/django/django/commit/c1c163b42717ed5e051098ebf0e2f5c77810f20e), maybe we could leverage this.
Or maybe insert an additional clause here: https://github.com/jazzband/django-debug-toolbar/blob/58f374a426a6b10dcf86554f6d9c71226b4b350f/debug_toolbar/panels/sql/views.py#L47-L55 -- that should work too and is probably a smaller change.
@matthiask Definitely, if Django does the abstraction for you, then that's the way to go.