question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refreshing causes old values to appear

See original GitHub issue

Hi,

I’ve been noticing a weird behaviour that we can’t seem to understand how to fix.

Once you edit a field in Flask Admin the values gets correctly saved to the database (I checked) but sometimes when refreshing the Flask Admin UI it displays the old values, seemingly at random.

You can see it in the following screen recording (I’m refreshing a few times).

flaskadmin

I’m using Python 3.6.3, Flask 0.12.2, flask-admin 1.5.0 and SQLAlchemy 1.1.15 and flask-sqlalchemy 2.3.2

It seems like it’s not correctly refreshing the session.

I’ve even tried with the following but to no avail:

from flask_admin.contrib.sqla import ModelView
class BaseView(ModelView):
    def after_model_change(self, form, model, is_created):
        self.session.expire_all()
        self.session.remove()

How can I fix it?

Thank you

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
rhymescommented, Jan 22, 2018

After googling, reading http://docs.sqlalchemy.org/en/latest/orm/contextual.html, https://github.com/mitsuhiko/flask-sqlalchemy/issues/99 and http://flask.pocoo.org/docs/0.12/reqcontext/#callbacks-and-errors

I ended up with the following, expiring the session and removing it after each request.

Keep in mind I’m not using threading, just gunicorn with two processes.

@app.teardown_request
def teardown_request(*args, **kwargs):
    'Expire and remove the session after each request'

    from models import db
    db.session.expire_all()
    db.session.remove()

where db is my SQLAlchemy object in Flask.

I’m not sure why it isn’t the default but it is working.

0reactions
JonathanBrennercommented, Oct 24, 2022

Ran into this today and @rhymes fix worked. flask==2.2.2 flask-admin==1.6.0 flask-sqlalchemy==2.5.1 sqlalchemy==1.4.41

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks useCallback keeps using old values when ...
So whats happening here is that the useCallback is closing over the state variables for that particular render, So the console.log even after...
Read more >
Solved: Gallery refresh overwrites old values in gallery - Page 3
Solved: Hi I need help to stop the gallery overwrite old values when a patch occurs on the textbox placed in the gallery....
Read more >
How to update old content to boost your traffic
3 reasons to include content refreshing in your content marketing strategy ... Old URLs have a lot of value because they've accumulated ...
Read more >
Local Variables - Appian 22.4
localVariables function refresh when a referenced variable in the value configuration changes. You can change these refresh behaviors using the a!
Read more >
Refresh Extracts - Tableau
Note: You can also automate extract refreshes using the Tableau Data ... you will be unable to open the extract with previous versions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found