From 3cdbb0b40f0ca101de7ca99640959a47dda9a8ca Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Mon, 22 Oct 2018 21:40:26 +0530 Subject: [PATCH] feat(recorder): Record stack for each frappe.db.sql call --- frappe/app.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frappe/app.py b/frappe/app.py index b3f806370e..70e0d11f58 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -47,11 +47,21 @@ def recorder(function): # Execute wrapped function as is # Record arguments as well as return value result = function(*args, **kwargs) + + import traceback + stack = "".join(traceback.format_stack()) + + # Big hack here + # PyMysql stores exact DB query in cursor._executed + # Assumes that function refers to frappe.db.sql + # __self__ will refer to frappe.db + # Rest is trivial data = { "function": function.__name__, "args": args, "kwargs": kwargs, "result": result, + "stack": stack } # Record all calls, Will be later stored in cache