From c83a9a142b9cafb77df3fbf241d4f66ba53789b0 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 12 Aug 2020 21:08:58 +0530 Subject: [PATCH] fix(minor): mogrify --- frappe/__init__.py | 2 +- frappe/database/database.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index c22899788e..36a8b48ecd 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -291,7 +291,7 @@ def errprint(msg): error_log.append({"exc": msg}) def print_sql(enable=True): - return cache().set_value('print_sql', enable) + return cache().set_value('flag_print_sql', enable) def log(msg): """Add to `debug_log`. diff --git a/frappe/database/database.py b/frappe/database/database.py index f5368df98f..97e86a03e7 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -193,23 +193,26 @@ class Database(object): return self._cursor.fetchall() def log_query(self, query, values, debug, explain): + def mogirfy(): + try: + return self._cursor.mogrify(query, values) + except TypeError: + return [query, values] + # for debugging in tests - if frappe.flags.in_test and frappe.cache().get_value('print_sql'): - print(self._cursor.mogrify(query, values)) + if frappe.flags.in_test and frappe.cache().get_value('flag_print_sql'): + print(mogrify()) # debug if debug: if explain and query.strip().lower().startswith('select'): self.explain_query(query, values) - frappe.errprint(self._cursor.mogrify(query, values)) + frappe.errprint(mogrify()) # info if (frappe.conf.get("logging") or False)==2: frappe.log("<<<< query") - frappe.log(query) - if values: - frappe.log("with values:") - frappe.log(values) + frappe.log(mogrify()) frappe.log(">>>>")