Skip to content

Commit 0c552d3

Browse files
committed
use try-catch import sqlite3, update action
1 parent 328a76c commit 0c552d3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

.github/workflows/main.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
- uses: actions/checkout@v3
2424
- uses: actions/setup-python@v4
2525
with:
26-
python-version: '3.6'
26+
python-version: '3.7'
27+
check-latest: true
2728
- name: Setup databases
2829
run: |
2930
pip install .
@@ -54,6 +55,7 @@ jobs:
5455
echo ::set-output name=version::$(python3 setup.py --version)
5556
5657
- name: Create Release
58+
if: ${{ github.ref == 'refs/heads/main' }}
5759
uses: actions/github-script@v6
5860
with:
5961
github-token: ${{ github.token }}

src/cs50/sql.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ def __init__(self, url, **kwargs):
5353
import sqlalchemy
5454
import sqlalchemy.orm
5555
import threading
56+
57+
# Temporary fix for missing sqlite3 module on the buildpack stack
58+
try:
59+
import sqlite3
60+
except:
61+
pass
5662

5763
# Require that file already exist for SQLite
5864
matches = re.search(r"^sqlite:///(.+)$", url)
5965
if matches:
60-
import sqlite3
6166
if not os.path.exists(matches.group(1)):
6267
raise RuntimeError("does not exist: {}".format(matches.group(1)))
6368
if not os.path.isfile(matches.group(1)):
@@ -75,7 +80,7 @@ def __init__(self, url, **kwargs):
7580
def connect(dbapi_connection, connection_record):
7681

7782
# Enable foreign key constraints
78-
if "sqlite3" in sys.modules and type(dbapi_connection) is sqlite3.Connection: # If back end is sqlite
83+
if type(dbapi_connection) is sqlite3.Connection: # If back end is sqlite
7984
cursor = dbapi_connection.cursor()
8085
cursor.execute("PRAGMA foreign_keys=ON")
8186
cursor.close()

0 commit comments

Comments
 (0)