2
0
mirror of https://github.com/frappe/frappe.git synced 2024-06-12 22:42:20 +00:00

fix(recorder): handle frappe.db.sql(run=0) (#25450)

This commit is contained in:
Ankush Menat 2024-03-14 23:17:37 +05:30 committed by GitHub
parent dbe55d4ace
commit df2b9c0983
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -59,12 +59,17 @@ def record_sql(*args, **kwargs):
result = frappe.db._sql(*args, **kwargs)
end_time = time.monotonic()
query = getattr(frappe.db, "last_query", None)
if not query or isinstance(result, str):
# run=0, doesn't actually run the query so last_query won't be present
return result
stack = []
if frappe.local._recorder.config.capture_stack:
stack = list(get_current_stack_frames())
data = {
"query": str(frappe.db.last_query),
"query": str(query),
"stack": stack,
"explain_result": [],
"time": start_time,

View File

@ -83,6 +83,7 @@ class TestRecorder(FrappeTestCase):
def test_explain(self):
frappe.db.sql("SELECT * FROM tabDocType")
frappe.db.sql("COMMIT")
frappe.db.sql("select 1", run=0)
self.stop_recording()
requests = frappe.recorder.get()