Skip to content

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

@markhobson

Description

@markhobson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions