From 8a62b135e2b8598311339a9cc88cd7d2108bf92c Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Mon, 22 Oct 2018 21:36:22 +0530 Subject: [PATCH] fix(recorder): Serialize Datetime objects with str() --- frappe/app.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frappe/app.py b/frappe/app.py index 5a1ba0da26..f872f79bc9 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -64,6 +64,9 @@ def recorder(function): wrapper.path = frappe.request.path return wrapper +def dumps(stuff): + return json.dumps(stuff, default=lambda x: str(x)) + def persist(function): """Stores recorded requests and calls in redis cache with following hierarchy @@ -108,7 +111,11 @@ def persist(function): # LPUSH -> Chronological order for calls # Since every request uuid is unique, no need for any heirarchy - frappe.cache().rpush("recorder-calls-{}".format(uuid), calls) + + # Datetime objects cannot be used with json.dumps + # str() seems to work with them + calls = map(dumps, calls) + frappe.cache().rpush("recorder-calls-{}".format(uuid), *calls) @Request.application def application(request):