check if conn is set before attempting to close it w/ burnettk

This commit is contained in:
jasquat 2023-06-12 14:29:22 -04:00
parent ddd9284eef
commit 30bb4c6b97
No known key found for this signature in database

View File

@ -10,9 +10,8 @@ class ConnectionConfig:
self.password = password
class BaseCommand:
"""BaseCommand."""
def _execute(self, sql, conn_str, handler):
conn = None
try:
conn = psycopg2.connect(conn_str)
with conn.cursor() as cursor:
@ -27,7 +26,8 @@ class BaseCommand:
status = 500
response = f'{"error": "Error executing sql statement: {e}"}'
finally:
conn.close()
if conn is not None:
conn.close()
return {"response": response, "status": status, "mimetype": "application/json"}