diff --git a/src/flask_session/sessions.py b/src/flask_session/sessions.py index a4346f2b..98322241 100644 --- a/src/flask_session/sessions.py +++ b/src/flask_session/sessions.py @@ -433,7 +433,9 @@ def fetch_session_sid(self, sid): store_id = self.key_prefix + sid saved_session = self.sql_session_model.query.filter_by( session_id=store_id).first() - if saved_session and saved_session.expiry <= datetime.utcnow(): + if saved_session and ( + not saved_session.expiry or saved_session.expiry <= datetime.utcnow() + ): # Delete expired session self.db.session.delete(saved_session) self.db.session.commit()