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

Autodelete sessions in SqlAlchemySessionInterface #117

Closed
wants to merge 1 commit into from

Conversation

Kolarovszki
Copy link

The expired sessions are not deleted from the database in every case, so
the autodeletion of expired sessions has been implemented.

Deletion of the expired sessions (e.g. with a cronjob) would be feasible
in the application, but it is nicer to implement it directly in
flask-session.

The autodeletion be enabled by the SESSION_AUTODELETE config variable,
which defaults to False.

Major drawback: it slows down open_session.

The expired sessions are not deleted from the database in every case, so
the autodeletion of expired sessions has been implemented.

Deletion of the expired sessions (e.g. with a cronjob) would be feasible
in the application, but it is nicer to implement it directly in
flask-session.

The autodeletion be enabled by the `SESSION_AUTODELETE` config variable,
which defaults to `False`.

Major drawback: it slows down `open_session`.
Copy link

@steinsag steinsag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to have that for all DB-based backends, also like Mongo storage.

@@ -561,3 +568,13 @@ def save_session(self, app, session, response):
response.set_cookie(app.session_cookie_name, session_id,
expires=expires, httponly=httponly,
domain=domain, path=path, secure=secure)

def delete_expired_sessions(self):
expired_sessions = self.sql_session_model.query.filter(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simplify that to something like:

self.sql_session_model.query.filter(self.sql_session_model.expiry < datetime.utcnow()).delete()
self.db.session.commit()

@bdouxx
Copy link

bdouxx commented Sep 20, 2021

hi,
something is blocking this request?
I'm very interested in this feature

christopherpickering added a commit to christopherpickering/flask-session2 that referenced this pull request Aug 17, 2022
@Lxstr
Copy link
Contributor

Lxstr commented Feb 25, 2024

Both these features is now included in 0.7.0 PR #212 as flask session_cleanup command and alternatively, SESSION_CLEANUP_N_REQUESTS. Also added direct TTL for mongo so there should be no cleanup required.

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

Successfully merging this pull request may close these issues.

4 participants