-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlAlchemy: TypeError if SESSION_PERMANENT=False #67
Comments
Same bug for mongodb backend. |
I made this fix for Mongo when testing with curl
Worked for me |
@negappan could you pull request? |
Same issue in PostgreSql |
Same here, solved with:
|
is there any way to fix this without changing the app code? We are experiencing this bug on AWS Airflow 2.4.3 and we cant really change airflow's version there |
I have the same problem with a fresh installation on AWS Airflow 2.4.3 |
For what is worth, clearing browser data seems to 'fix' the issue |
Yes, clearing the session data fix the access but temporarily until the session expires again. I've experienced the issue more times |
Hi @Danipiario , |
So far the workaround works |
FYI I have found a fork of this project on Pypi flask-session2 that is actively maintained and does not have this problem. I was able to use it in my project as a drop-in replacement. |
Fixed since 0.6.0. Please report any further issues |
It doesn't give error but now nothing interesting happens. After setting up session, it returns None if you try to retrieve session data. |
@HammadAwan424 can you show me a minimum example? Also can you try 0.7.0rc2? If you are upgrading from 0.5.0 while there are existing sessions, it will remove those sessions that had expiry None. |
Using SqlAlchemy (both with mysql and sqlite) if I set SESSION_PERMANENT to False the system return a TypeError
Changing the SESSION_TYPE in filesystem the system works and the cookie will be deleted when the browser is closed.
On the DB table the session row has the expiry row empty.
Expiry comes from expires variable tha is set on row 547:
expires = self.get_expiration_time(app, session)
get_expiration_time is a flask fuction that returns the expiration date for the session:
That's why the expiry field on sessions table is empty, a cookie set as non-permanent doesn't have a expiration date. So it's not possible for mysql and sqlite to check a NULL date.
To populate the expiry field in the DB table I changed:
expires = self.get_expiration_time(app, session)
into
No more error but if i close the browser the ,session cookie is still there.
That's because the set_cookie function must have expires empty to delete the cookie when browser is closed.
So I changed:
expires = self.get_expiration_time(app, session)
into
And on line 561 I changed:
into
I hope that this could by helpful and clear.
UPDATE
Another way, more elegant, to solve the problem is to check self.permanent before checking if saved_session.expire is outdated.
On line 516 change
if saved_session and saved_session.expiry <= datetime.utcnow():
into something like
if self.permanent and saved_session and saved_session.expiry <= datetime.utcnow():
Also this solution works but, if I'm not wrong, in this way the session will never be deleted from the DB table and, more important, it will never be tested. That's could be a security problem.
In the other solution the expiration date is written to the DB. In that case the problem may be that for a time a cookie remains active even if on the browser has already been deleted. I do not know if this could be considered a security problem.
UPDATE IE11 issue
On IE11 you cannot have a
Expires=;
, otherwise the cookie will never be stored.For now I solved brutally with an
if
onThe text was updated successfully, but these errors were encountered: