flask-session
flask-session copied to clipboard
Session failing when used with MongoDB due to datetime error
I'm using session with MongoDB and it fails because of a datetime error. TypeError: can't compare offset-naive and offset-aware datetimes
File "/Library/Python/2.7/site-packages/flask/app.py", line 2000, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1984, in wsgi_app
ctx.push()
File "/Library/Python/2.7/site-packages/flask/ctx.py", line 332, in push
self.session = self.app.open_session(self.request)
File "/Library/Python/2.7/site-packages/flask/app.py", line 914, in open_session
return self.session_interface.open_session(self, request)
File "/Library/Python/2.7/site-packages/flask_session/sessions.py", line 411, in open_session
if document and document.get('expiration') <= datetime.utcnow():
TypeError: can't compare offset-naive and offset-aware datetimes
I had recently faced a similar issue while checking expiry of a token. Handled it with using a different datetime format.
I believe we need to use any other format like: datetime.datetime.strptime(<timeStamp>,"%d %b %Y %I:%M:%S %p")
Mongo Version : 3.4 Flask-Session==0.3.0
This issue was moved to mcrowson/flask-session#1
It seems the mongodb python client returns an offset-aware datetime even though we put a offset-naive datetime in it.
This was fixed in 0.6.0 and will be entirely eliminated from 0.7.0 by using time-to-live in mongo.