Open andreyv opened 6 years ago
The actual problem is visible in the logs: Uncaught exception in write_error
.
The problem seems to be because when the template is rendered and render_params()
is called, self.url
is None
. self.url
is assigned in CommonRequestHandler.prepare()
.
Could it be that prepare()
has not been called at the time the error template is rendered in write_error()
?
Indeed, on both occasions prepare()
has not been called at the time the error is processed.
This change fixes the first failure:
diff --git a/cms/server/contest/handlers/contest.py b/cms/server/contest/handlers/contest.py
index be2f333a..1e91c3de 100644
--- a/cms/server/contest/handlers/contest.py
+++ b/cms/server/contest/handlers/contest.py
@@ -64,6 +64,8 @@ class ContestHandler(BaseHandler):
self.contest_url = None
def prepare(self):
+ super().prepare()
+
self.choose_contest()
if self.contest.allowed_localizations:
@@ -74,8 +76,6 @@ class ContestHandler(BaseHandler):
(k, v) for k, v in self.available_translations.items()
if k in lang_codes)
- super().prepare()
-
if self.is_multi_contest():
self.contest_url = self.url[self.contest.name]
else:
The XSRF error is harder because the check is called just before prepare()
in Tornado code:
I see about three ways to solve this:
self.url
assignment from prepare()
to __init__()
(self.request
is already defined at that time)self.render_params()
to raise an exception if self.url
is None
. This way write_error()
can catch it and fall back to a simple error page.Thoughts?
If I understand correctly, this is now fixed in ContestWebServer but still broken in AdminWebServer.
Steps to reproduce:
localhost:8888
telnet localhost 8888
HTTP/1.1 404 Not Found Server: TornadoServer/4.5.3 Content-Type: text/html; charset=UTF-8 Date: Tue, 06 Nov 2018 18:25:50 GMT Content-Length: 224 Set-Cookie: zzz_login=""; expires=Mon, 06 Nov 2017 18:25:50 GMT; Path=/ Set-Cookie: _xsrf=2|47f2b7e0|d92adbae5745d453d5769a29a88df401|1541528750; Path=/
<!DOCTYPE html>