[QUESTION] No teardown_appcontext?
See original GitHub issuePreviously with Flask I wanted to remove database upon shutdown :
database.py
db_session = scoped_session(sessionmaker(.....)
app.py
from database import db_session
@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
But with FastAPI:
AttributeError: ‘FastAPI’ object has no attribute ‘teardown_appcontext’
What to do please?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Flask app.teardown_appcontext not being called when ...
I finally found the problem and it was actually a side effect of using Flask-Script with Flask-SqlAlchemy. If SQLAlchemy is instantiated ...
Read more >Solved add queries help!! This is a part of a code, writing | Chegg.com
Question : add queries help!! ... connection @app.teardown_appcontext def close_connection(exception): db = getattr(g, '_database', None) if db is not None: ...
Read more >Using SQLite 3 with Flask — Flask Documentation (2.2.x)
In Flask you can easily implement the opening of database connections on demand and closing them when the context dies (usually at the...
Read more >Step 4: Database Connections - Flask 0.13.dev documentation
Functions marked with teardown_appcontext() are called every time the app context tears down. What does this mean? Essentially, the app context is created ......
Read more >The mysterious Flask Application Context, my questions and ...
The application context is initialized, pushed and popped, for a first time user things can be confusing. Time to start reading.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://fastapi.tiangolo.com/tutorial/events/#shutdown-event
Above link is expired, here is the updated link https://fastapi.tiangolo.com/advanced/events/#events-startup-shutdown .