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

>0.6.0 breaks session['last_active'] #255

Closed jeroen-80 closed 2 weeks ago

jeroen-80 commented 3 weeks ago

For a session lifetime check I use the following code:

now = datetime.datetime.now()
delta = now - session['last_active'].replace(tzinfo=None)
[..]

Worked fine for years, until an upgrade to 0.8.0 (and a check on 0.7.0):

delta = now - session['last_active'].replace(tzinfo=None)
TypeError: replace() takes no keyword arguments

Seems that the type changed in 0.7.0? How to fix?

Lxstr commented 2 weeks ago

The changelog https://flask-session.readthedocs.io/en/latest/changes.html and the rest of the documentation shows that the session itself has not changed types but the default serializer has for a number of reasons. This is also mentioned in the documentation.

This means certain types may not serialize well as objects, you can see further infomation at the msgspec documentation. You could consider storing the last_active as a string and converting to datetime object. Hope that helps?

jeroen-80 commented 2 weeks ago

Hope that helps?

It does, thank you!