From d08faa89872d9ec8d3c8e76d85164ccd84596811 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 29 Jun 2018 07:52:51 -0500 Subject: [PATCH] Fix for weird nested exception in RequestTimeout I saw this error: sanic.exceptions.RequestTimeout: Request Timeout During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/simonw/Dropbox/Development/datasette/venv/lib/python3.6/site-packages/sanic/handlers.py", line 82, in response response = handler(request=request, exception=exception) File "/Users/simonw/Dropbox/Development/datasette/datasette/app.py", line 512, in on_exception if request.path.split("?")[0].endswith(".json"): AttributeError: 'NoneType' object has no attribute 'path' Strangely "if request and request.path..." did not work here, because the Sanic Request class extends builtins.dict and hence evaluates to False if it has no headers. --- datasette/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datasette/app.py b/datasette/app.py index 7466c42c..5b93ea20 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -509,7 +509,7 @@ class Datasette: info.update( {"ok": False, "error": message, "status": status, "title": title} ) - if request.path.split("?")[0].endswith(".json"): + if request is not None and request.path.split("?")[0].endswith(".json"): return response.json(info, status=status) else: