aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--famille.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/famille.py b/famille.py
index d7a0e5f..207d3ac 100644
--- a/famille.py
+++ b/famille.py
@@ -81,15 +81,17 @@ def connect_db():
return conn
def get_db():
- if not hasattr(g, 'sqlite_db'):
- g.sqlite_db = connect_db()
- return g.sqlite_db
+ db = getattr(g, 'sqlite_db', None)
+ if db is None:
+ db = g.sqlite_db = connect_db()
+ return db
@app.teardown_appcontext
def close_db(error):
"""Closes the database again at the end of the request."""
- if hasattr(g, 'sqlite_db'):
- g.sqlite_db.close()
+ db = getattr(g, 'sqlite_db', None)
+ if db:
+ db.close()
def login_required(f):
@wraps(f)