diff --git a/atst/routes/errors.py b/atst/routes/errors.py index 56551ee0..039ae635 100644 --- a/atst/routes/errors.py +++ b/atst/routes/errors.py @@ -8,7 +8,6 @@ from atst.domain.invitations import ( ExpiredError as InvitationExpiredError, WrongUserError as InvitationWrongUserError, ) -from atst.utils.form_cache import cache_form_data def log_error(e): @@ -40,7 +39,7 @@ def make_error_pages(app): log_error(e) url_args = {"sessionExpired": True, "next": request.path} if request.method == "POST": - url_args["formCache"] = cache_form_data(app.redis, request.form) + url_args["formCache"] = app.form_cache.write(request.form) return redirect(url_for("atst.root", **url_args)) @app.errorhandler(Exception) diff --git a/atst/utils/form_cache.py b/atst/utils/form_cache.py index f199bdc5..8ee831b7 100644 --- a/atst/utils/form_cache.py +++ b/atst/utils/form_cache.py @@ -32,10 +32,11 @@ class FormCache(object): value = pickle.dumps(formdata) hash_ = hashlib.sha1(os.urandom(64)).hexdigest() self.redis.setex(name=self._key(key_prefix, hash_), value=value, time=expiry_seconds) + return hash_ def read(self, formdata_key, key_prefix="formcache"): data = self.redis.get(self._key(key_prefix, formdata_key)) - return pickle.loads(data) + return pickle.loads(data) if data is not None else {} @staticmethod def _key(prefix, hash_):