Skip to content

Commit 3ccbd99

Browse files
committedDec 2, 2022
added try-catch workaround for SQL.connect when sqlite3 is not available
1 parent 0c552d3 commit 3ccbd99

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
package_dir={"": "src"},
1919
packages=["cs50"],
2020
url="https://github.com/cs50/python-cs50",
21-
version="9.2.3"
21+
version="9.2.4"
2222
)

‎src/cs50/sql.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,14 @@ def __init__(self, url, **kwargs):
8080
def connect(dbapi_connection, connection_record):
8181

8282
# Enable foreign key constraints
83-
if type(dbapi_connection) is sqlite3.Connection: # If back end is sqlite
84-
cursor = dbapi_connection.cursor()
85-
cursor.execute("PRAGMA foreign_keys=ON")
86-
cursor.close()
83+
try:
84+
if type(dbapi_connection) is sqlite3.Connection: # If back end is sqlite
85+
cursor = dbapi_connection.cursor()
86+
cursor.execute("PRAGMA foreign_keys=ON")
87+
cursor.close()
88+
except:
89+
# Temporary fix for missing sqlite3 module on the buildpack stack
90+
pass
8791

8892
# Register listener
8993
sqlalchemy.event.listen(self._engine, "connect", connect)

0 commit comments

Comments
 (0)
Please sign in to comment.