Skip to content

Commit

Permalink
fix(recorder): handle frappe.db.sql(run=0) (#25450) (#25454)
Browse files Browse the repository at this point in the history
(cherry picked from commit df2b9c0)

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Mar 15, 2024
1 parent 07aadd3 commit d130777
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion frappe/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions frappe/tests/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_record_with_sql_queries(self):
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()
Expand Down

0 comments on commit d130777

Please sign in to comment.