From 369679bae512760558c285878f861b27d59becb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 13 Feb 2019 16:12:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Work=20around=20CPython=20bug=20?= =?UTF-8?q?bpo-29097?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/server/util/flask.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index e9f7f96e6..2de28ef1a 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -1120,7 +1120,12 @@ def check_lastmodified(lastmodified): from datetime import datetime if isinstance(lastmodified, (int, long, float)): - lastmodified = datetime.fromtimestamp(lastmodified).replace(microsecond=0) + # max(86400, lastmodified) is workaround for https://bugs.python.org/issue29097, + # present in CPython 3.6.x up to 3.7.1. + # + # I think it's fair to say that we'll never encounter lastmodified values older than + # 1970-01-02 so this is a safe workaround. + lastmodified = datetime.fromtimestamp(max(86400, lastmodified)).replace(microsecond=0) if not isinstance(lastmodified, datetime): raise ValueError("lastmodified must be a datetime or float or int instance but, got {} instead".format(lastmodified.__class__))