fix: db explain (#25724)

This broke from some recent changes.

It's just a wrapper, so probably no one uses it.
Anyway, fixed and added test to prevent it.
This commit is contained in:
Ankush Menat 2024-03-29 15:53:12 +05:30 committed by GitHub
parent e8fe24d7df
commit de48dc2c04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View file

@ -389,15 +389,15 @@ class Database:
"""Wrap the object with str to generate mogrified query."""
return LazyMogrify(query, values)
def explain_query(self, query, values=None):
def explain_query(self, query, values=EmptyQueryValues):
"""Print `EXPLAIN` in error log."""
frappe.log("--- query explain ---")
try:
self._cursor.execute(f"EXPLAIN {query}", values)
results = self.sql(f"EXPLAIN {query}", values, as_dict=1)
except Exception as e:
frappe.log(f"error in query explain: {e}")
else:
frappe.log(json.dumps(self.fetch_as_dict(), indent=1))
frappe.log(json.dumps(results, indent=1))
frappe.log("--- query explain end ---")
def sql_list(self, query, values=(), debug=False, **kwargs):

View file

@ -618,6 +618,9 @@ class TestDB(FrappeTestCase):
self.assertEqual(order_of_execution, list(range(0, 9)))
def test_db_explain(self):
frappe.db.sql("select 1", debug=1, explain=1)
@run_only_if(db_type_is.MARIADB)
class TestDDLCommandsMaria(FrappeTestCase):