diff --git a/muk_session_store/__manifest__.py b/muk_session_store/__manifest__.py index f8b2bc3..ce8f8a8 100644 --- a/muk_session_store/__manifest__.py +++ b/muk_session_store/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Session Store", "summary": """Session Store Options""", - "version": "12.0.1.0.1", + "version": "12.0.1.0.2", "category": "Extra Tools", "license": "AGPL-3", "website": "http://www.mukit.at", diff --git a/muk_session_store/store/postgres.py b/muk_session_store/store/postgres.py index fcf1532..8aacc58 100644 --- a/muk_session_store/store/postgres.py +++ b/muk_session_store/store/postgres.py @@ -23,6 +23,7 @@ import psycopg2 import functools from contextlib import closing +from datetime import datetime, date from werkzeug.contrib.sessions import SessionStore @@ -101,10 +102,19 @@ class PostgresSessionStore(SessionStore): def get(self, sid): if not self.is_valid_key(sid): return self.new() - self.cursor.execute("UPDATE sessions SET write_date = now() at time zone 'UTC' WHERE sid=%s;", [sid]) - self.cursor.execute("SELECT payload FROM sessions WHERE sid=%s;", [sid]) + self.cursor.execute(""" + SELECT payload, write_date + FROM sessions WHERE sid=%s; + """, [sid]) try: - return self.session_class(json.loads(self.cursor.fetchone()[0]), sid, False) + payload, write_date = self.cursor.fetchone() + if write_date.date() != datetime.today().date(): + self.cursor.execute(""" + UPDATE sessions + SET write_date = now() at time zone 'UTC' + WHERE sid=%s; + """, [sid]) + return self.session_class(json.loads(payload), sid, False) except Exception: return self.session_class({}, sid, False)