From c0b24da2f46da4abe15a9afd95f6ffa289c97853 Mon Sep 17 00:00:00 2001 From: Kareem Zidane Date: Mon, 13 Jan 2020 18:22:36 -0500 Subject: [PATCH] disconnecting only if there's a connection --- setup.py | 2 +- src/cs50/sql.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 7da3cdd..097fed4 100644 --- a/setup.py +++ b/setup.py @@ -16,5 +16,5 @@ package_dir={"": "src"}, packages=["cs50"], url="https://github.com/cs50/python-cs50", - version="5.0.1" + version="5.0.2" ) diff --git a/src/cs50/sql.py b/src/cs50/sql.py index 484f5ad..ae8e59c 100644 --- a/src/cs50/sql.py +++ b/src/cs50/sql.py @@ -281,7 +281,8 @@ def execute(self, sql, *args, **kwargs): # Disconnect later @flask.current_app.teardown_appcontext def shutdown_session(exception=None): - flask.g._connection.close() + if hasattr(flask.g, "_connection"): + flask.g._connection.close() # Use this connection connection = flask.g._connection