pallets-eco / flask-session

Server side session extension for Flask
https://flask-session.readthedocs.io
BSD 3-Clause "New" or "Revised" License
501 stars 239 forks source link

Session not saving #119

Closed NeuroAssassin closed 1 year ago

NeuroAssassin commented 4 years ago

Hey there. I've been using flask-session for a while now, and I have had one moderate continuous problem throughout, and with the new update, I'm having a major issue.

First, with the new update switching to cachelib, I can't set anything in session. I have a button that sends a web request to another endpoint on my site, which sets a variable in session using session['theme'], but when I reload the page, it's back to how it was.

Second, I've noticed that quite a lot, the session will just... refresh. I'll lose everything I have in my cookies, resetting my authorization and also the theme I have set, which can be real annoying.

If you could fix the above issues, or point me to what I'm doing wrong, that'd be great. If you want to take a look at the code I'm using, head to the Toxic-Cogs repo on my account, then look in dashboard\data on the dashboard-testing branch. Thanks.

snjypl commented 4 years ago

@NeuroAssassin this issue is because of an bug in cachelib . pallets/cachelib/pull/12. on windows cachelib set fails when the cache file already exist. it need to be fixed in cachelib by chaning os.rename to os.replace.

in cachelib the error is suppressed and instead it returned False. probably in https://github.com/fengsp/flask-session/blob/master/flask_session/sessions.py#L353 the return code needs to be checked and probably raise an exception.

NeuroAssassin commented 4 years ago

@snjypl Thanks for getting back. Great to know that that issue has been seen. Do you know anything about the issue with the session resetting constantly though? I was getting that before I updated.

Adityashaw commented 4 years ago

@NeuroAssassin this issue is because of an bug in cachelib . pallets/cachelib/pull/12.

That pull seems to be merged. I still have the issue. What to do?

snjypl commented 4 years ago

you can try installing it from git

pip install git+https://github.com/pallets/cachelib.git@master

GChalony commented 4 years ago

Been searching for a week to finally narrow it down to flask-session update (I was using werkzeug < 1 before v0.3.2).
Thanks for the info ! Unfortunately I think it means downgrading again in the meanwhile...

rayluo commented 4 years ago

@NeuroAssassin @snjypl @Adityashaw @GChalony

That upstream fix (https://github.com/pallets/cachelib/pull/12) was released in its 0.1.1 version 7 hours ago. And, given that flask-session currently always picks up latest version of cachelib, you should be able to update your environment and then test it out.

christopherpickering commented 1 year ago

Closing as fixed w/ @rayluo comment. please comment back or open a new issue if there is still problem.