From 035cbf84ae4454422b6dbd1861401404963f7e6b Mon Sep 17 00:00:00 2001 From: Hyunjun Kim Date: Mon, 2 Jan 2017 14:20:20 +0900 Subject: [PATCH 1/2] Cache request.json even when it's null or empty In case of request body is set to `{}`, `[]` or `null`, even it's already processed, parsed_json won't be used due to its boolean evaluation. --- sanic/request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index 4309bbed..a9f0364d 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -56,7 +56,7 @@ class Request(dict): # Init but do not inhale self.body = None - self.parsed_json = None + self.parsed_json = ... self.parsed_form = None self.parsed_files = None self.parsed_args = None @@ -64,7 +64,7 @@ class Request(dict): @property def json(self): - if not self.parsed_json: + if self.parsed_json is ...: try: self.parsed_json = json_loads(self.body) except Exception: From baf8254907720cb35212f00afa48787fa8558b6b Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Thu, 5 Jan 2017 15:29:57 -0600 Subject: [PATCH 2/2] Change Ellipsis to None for consistency --- sanic/request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index a9f0364d..7ca5523c 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -56,7 +56,7 @@ class Request(dict): # Init but do not inhale self.body = None - self.parsed_json = ... + self.parsed_json = None self.parsed_form = None self.parsed_files = None self.parsed_args = None @@ -64,7 +64,7 @@ class Request(dict): @property def json(self): - if self.parsed_json is ...: + if self.parsed_json is None: try: self.parsed_json = json_loads(self.body) except Exception: