Skip to content
Myr

Merge pull request #4645 from kkirsche/patch-2

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Use timezone aware datetime object on session

authored by David Lord · committed by GitHub · parents cec5f74, ed42e92 · Browse files · 3 files+7 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+7 added−3 removed

  • tests:+3 added−2 removed
  • other:+4 added−1 removed

3 files+7 added−3 removed

modified:src/flask/sessions.py+2 added-1 removed
1 unmodified line
2import typing as t3import warnings4from collections.abc import MutableMapping5from datetime import datetime6from datetime import timezone78from itsdangerous import BadSignature9from itsdangerous import URLSafeTimedSerializer10from werkzeug.datastructures import CallbackDict
266 unmodified lines
277 default implementation returns now + the permanent session278 lifetime configured on the application.279 """280 if session.permanent:280 return datetime.utcnow() + app.permanent_session_lifetime281 return datetime.now(timezone.utc) + app.permanent_session_lifetime282 return None283284 def should_set_cookie(self, app: "Flask", session: SessionMixin) -> bool:285 """Used by session backends to determine if a ``Set-Cookie`` header
137 unmodified lines
modified:tests/test_basic.py+3 added-2 removed
3 unmodified lines
4import uuid5import warnings6import weakref7from datetime import datetime8from datetime import timezone9from platform import python_implementation10from threading import Thread1112import pytest
423 unmodified lines
436 rv = client.get("/")437 assert "set-cookie" in rv.headers438 match = re.search(r"(?i)\bexpires=([^;]+)", rv.headers["set-cookie"])439 expires = parse_date(match.group())439 expected = datetime.utcnow() + app.permanent_session_lifetime440 expected = datetime.now(timezone.utc) + app.permanent_session_lifetime441 assert expires.year == expected.year442 assert expires.month == expected.month443 assert expires.day == expected.day444
21 unmodified lines
466 assert client.get("/").data == b"42"467468469def test_session_special_types(app, client):469 now = datetime.utcnow().replace(microsecond=0)470 now = datetime.now(timezone.utc).replace(microsecond=0)471 the_uuid = uuid.uuid4()472473 @app.route("/")474 def dump_session_contents():
1550 unmodified lines
modified:CHANGES.rst+2 added
34 unmodified lines
35 ``.flaskenv``. :issue:`3108`36- It is no longer required to decorate custom CLI commands on37 ``app.cli`` or ``blueprint.cli`` with ``@with_appcontext``, an app38 context will already be active at that point. :issue:`2410`39- ``SessionInterface.get_expiration_time`` uses a timezone-aware40 value. :pr:`4645`414243Version 2.1.344-------------
1291 unmodified lines