Skip to content

Commit

Permalink
add tzinfo to expiry datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
GammaGames committed Jan 9, 2025
1 parent 7b5b5e8 commit 9e06b52
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/flask_session/sqlalchemy/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(
def _delete_expired_sessions(self) -> None:
try:
self.client.session.query(self.sql_session_model).filter(
self.sql_session_model.expiry.timestamp() <= datetime.now(timezone.utc)
self.sql_session_model.expiry.replace(tzinfo=timezone.utc) <= datetime.now(timezone.utc)
).delete(synchronize_session=False)
self.client.session.commit()
except Exception:
Expand All @@ -138,7 +138,7 @@ def _retrieve_session_data(self, store_id: str) -> Optional[dict]:
record = self.sql_session_model.query.filter_by(session_id=store_id).first()

# "Delete the session record if it is expired as SQL has no TTL ability
if record and (record.expiry is None or record.expiry.timestamp() <= datetime.now(timezone.utc)):
if record and (record.expiry is None or record.expiry.replace(tzinfo=timezone.utc) <= datetime.now(timezone.utc)):
try:
self.client.session.delete(record)
self.client.session.commit()
Expand Down

0 comments on commit 9e06b52

Please sign in to comment.