pallets-eco / flask-session

Server side session extension for Flask
https://flask-session.readthedocs.io
BSD 3-Clause "New" or "Revised" License
488 stars 236 forks source link

Fix datetime.utcnow() deprecations in SQLAlchemy backend #253

Open markhobson opened 1 month ago

markhobson commented 1 month ago

datetime.utcnow() is now deprecated in Python 3.12. It is used by the SQLAlchemy backend:

xxx/.venv/lib/python3.12/site-packages/flask_session/sqlalchemy/sqlalchemy.py:168: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    storage_expiration_datetime = datetime.utcnow() + session_lifetime

xxx/.venv/lib/python3.12/site-packages/flask_session/sqlalchemy/sqlalchemy.py:141: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    if record and (record.expiry is None or record.expiry <= datetime.utcnow()):

Happy to submit a PR given guidance on how timezones should be handled.