librelist archives

« back to archive

flask_login and heroku

flask_login and heroku

From:
Marcin Szamotulski
Date:
2013-09-26 @ 17:08
Hello,

I have a problem with an application running on heroku.  It is using
flask_login.  I boiled the problem down to the following two simple
views: 

@app.route('/fresh_session')
def fresh():
    from flask_login import confirm_login
    confirm_login()
    return redirect(url_for('index'))

@app.route('/unfresh_session')
def unfresh():
    from flask import session
    session['_fresh'] = False
    return redirect(url_for('index'))


The problem I observe on Heroku (but not locally) is that when I have a
not fresh session (for testing I made the unfresh view to make it
simpler), when I direct by browser (chrome, firefox) to the fresh view
it sets the session as fresh, but the redirection marks it not fresh again
(I used the excellent flask debug tool bar with intercept redirects)

As I have mentioned there is no problem locally, where I also traced the
problem with pdb and I haven't found anything that could make the
session not fresh (which as far as I read the code is only if user_id is
deleted from the session, so that it has to be restored from the session
cookie or when there was missing session id).


Any help in debugging/solving this problem is appreciated,

Thanks,
Marcin

Re: flask_login and heroku

From:
Marcin Szamotulski
Date:
2013-09-30 @ 13:11
Ok, the solution is to set
SERVER_NAME 
flask config variable on Heroku, just in case somebody will stumble on
this issue in the future.

app.config['SERVER_NAME'] = 'your-app-name.herokuapp.com'  # adjust as needed

Best regards,
Marcin Szamotulski


On 18:08 Thu 26 Sep     , Marcin Szamotulski wrote:
> Hello,
> 
> I have a problem with an application running on heroku.  It is using
> flask_login.  I boiled the problem down to the following two simple
> views: 
> 
> @app.route('/fresh_session')
> def fresh():
>     from flask_login import confirm_login
>     confirm_login()
>     return redirect(url_for('index'))
> 
> @app.route('/unfresh_session')
> def unfresh():
>     from flask import session
>     session['_fresh'] = False
>     return redirect(url_for('index'))
> 
> 
> The problem I observe on Heroku (but not locally) is that when I have a
> not fresh session (for testing I made the unfresh view to make it
> simpler), when I direct by browser (chrome, firefox) to the fresh view
> it sets the session as fresh, but the redirection marks it not fresh again
> (I used the excellent flask debug tool bar with intercept redirects)
> 
> As I have mentioned there is no problem locally, where I also traced the
> problem with pdb and I haven't found anything that could make the
> session not fresh (which as far as I read the code is only if user_id is
> deleted from the session, so that it has to be restored from the session
> cookie or when there was missing session id).
> 
> 
> Any help in debugging/solving this problem is appreciated,
> 
> Thanks,
> Marcin