From 3ccbd99c58d18df7e9385d421e85e8b7631bbe9d Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Fri, 2 Dec 2022 15:32:18 -0500 Subject: [PATCH] added try-catch workaround for SQL.connect when sqlite3 is not available --- setup.py | 2 +- src/cs50/sql.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 2d90788..62a7abe 100644 --- a/setup.py +++ b/setup.py @@ -18,5 +18,5 @@ package_dir={"": "src"}, packages=["cs50"], url="https://github.com/cs50/python-cs50", - version="9.2.3" + version="9.2.4" ) diff --git a/src/cs50/sql.py b/src/cs50/sql.py index 8087657..f2c090d 100644 --- a/src/cs50/sql.py +++ b/src/cs50/sql.py @@ -80,10 +80,14 @@ def __init__(self, url, **kwargs): def connect(dbapi_connection, connection_record): # Enable foreign key constraints - if type(dbapi_connection) is sqlite3.Connection: # If back end is sqlite - cursor = dbapi_connection.cursor() - cursor.execute("PRAGMA foreign_keys=ON") - cursor.close() + try: + if type(dbapi_connection) is sqlite3.Connection: # If back end is sqlite + cursor = dbapi_connection.cursor() + cursor.execute("PRAGMA foreign_keys=ON") + cursor.close() + except: + # Temporary fix for missing sqlite3 module on the buildpack stack + pass # Register listener sqlalchemy.event.listen(self._engine, "connect", connect)