From 85eada5021e197da4fe6fb3df18a324435c7fac7 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 1 Dec 2013 19:05:00 -0500 Subject: one more try --- famille.py | 12 +++++++----- 1 file 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) -- cgit v1.2.3-70-g09d2