According to the documentation for working with shell in Flask (link):
By just creating a request context, you still don’t have run the code that is normally run before a request. This might result in your database being unavailable if you are connecting to the database in a before-request callback or the current user not being stored on the g object etc.
This could be fixed by calling app.preprocess_request() explicitly. Similarly, to trigger the after_request functions, a trick is suggested like so: app.process_response(app.response_class()).
According to the documentation for working with shell in Flask (link):
This could be fixed by calling
app.preprocess_request()
explicitly. Similarly, to trigger theafter_request
functions, a trick is suggested like so:app.process_response(app.response_class())
.