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.

[QUESTION] No teardown_appcontext?

See original GitHub issue

Previously 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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

github_iconTop 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 >

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