Skip to content
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

session.clear() removes expiry field, causing TypeError #56

Closed
grutz opened this issue Jan 20, 2017 · 5 comments
Closed

session.clear() removes expiry field, causing TypeError #56

grutz opened this issue Jan 20, 2017 · 5 comments

Comments

@grutz
Copy link

grutz commented Jan 20, 2017

Setup: Flask 0.11, SQLAlchemy session interface, python 2.7.x

When using session.clear() to empty a session, say on a logout signal to ensure an empty session record, the expiry field is set to null in the database:

dev=# select session_id,expiry from sessions;
                  session_id                  | expiry
----------------------------------------------+--------
 session:ed53619f-84d7-4985-9383-260aa9817125 |
(1 row)

This causes a TypeError exception on line 516:

    if saved_session and saved_session.expiry <= datetime.utcnow():
        # Delete expired session
        self.db.session.delete(saved_session)
        self.db.session.commit()
        saved_session = None

Work-around solution is to check for saved_session.expiry before comparison:

    if saved_session and (not saved_session.expiry or saved_session.expiry <= datetime.utcnow()):
@mcrowson

This comment was marked as outdated.

@fengsp
Copy link
Contributor

fengsp commented Apr 5, 2017

I don't understand why expiry is null here :(

@johnnymetz

This comment was marked as off-topic.

@Tethik

This comment was marked as off-topic.

@Lxstr
Copy link
Contributor

Lxstr commented Mar 10, 2024

This was an issue where clear() was also clearing the _permanent in the session dict. Fixed post 0.7.0rc1

@Lxstr Lxstr closed this as completed Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants