DEV Community

mekkaouiredouane
mekkaouiredouane

Posted on

Flask app not updating fetched data from database without restart

Hi,
I'm having a problem with my Flask app where it doesn't update the data fetched from the database when I insert new data. The app only fetches the old data that was fetched when I started the app. No matter how much new data I insert, the fetched data doesn't update until I restart the Flask app by stopping it with ctrl+c and running it again with flask run.
I tried disabling the cache like this:

cache = Cache(app, config={'CACHE_TYPE': 'null'})

However, it didn't work. I also checked the user class, the queries, and the functions, and everything seems to be working perfectly and showing results. Additionally, I'm using commit like this:

cursor.execute(query, data)
self.conn.commit()

Here's my configuration:

`async_mode = None

app = Flask(name)

class MyApp:
def init(self):
self.app = app
self.app.add_url_rule('/', 'home', self.home,
methods=["GET", "POST"])
self.app.config['DEBUG'] = True
# Secure session configuration
self.app.config['SESSION_TYPE'] = 'filesystem'
self.app.config['SESSION_FILE_DIR'] = '/tmp/flask_session'
# Whether the session cookie should be secure (i.e., HTTPS only)
self.app.config['SESSION_COOKIE_SECURE'] = True
# Prevents JavaScript from accessing the session cookie
self.app.config['SESSION_COOKIE_HTTPONLY'] = True
self.app.config['SESSION_PERMANENT'] = False
self.app.config['SESSION_COOKIE_SAMESITE'] = 'Strict'
self.app.config['SECURITY_PASSWORD_SALT'] = 'password_salt'
# 'development', 'production', or 'testing'
self.app.config['ENV'] = 'development'
# Disables testing
self.app.config['TESTING'] = False
self.app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0

def run(self):
    self.app.run()`
Enter fullscreen mode Exit fullscreen mode

Is there any way to see the update without restarting the Flask app? Any help would be appreciated. Thanks in advance!

Top comments (0)