Skip to content

Commit

Permalink
Permanent fix for cs50 SQL bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jdabtieu committed Dec 18, 2023
1 parent ef26afd commit f5af4da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
20 changes: 1 addition & 19 deletions src/db.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
from cs50 import SQL as cs50_SQL
from cs50 import SQL
import sqlalchemy

Check warning on line 2 in src/db.py

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

F401 'sqlalchemy' imported but unused
import sys


# https://github.com/cs50/python-cs50/issues/178
if int(sqlalchemy.__version__.split('.')[0]) == 1:
SQL = cs50_SQL
else:
class SQL:
def __init__(self, url, **kwargs):
self.db = cs50_SQL(url, **kwargs)

def execute(self, query, *args, **kwargs):
try:
return self.db.execute(query, *args, **kwargs)
except ValueError as e:
if self.db._autocommit:
self.db._autocommit = False
self.db.execute("ROLLBACK")
raise e


try:
db = SQL("sqlite:///database.db")
except Exception as e: # when testing
Expand Down
3 changes: 2 additions & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ flask-session2==1.3.1
Flask-WTF==1.2.1
Flask==2.3.3
Werkzeug==3.0.*
cs50==9.3.0
cs50==9.3.3
pyjwt>=2.8.0
requests>=2.31.0
SQLAlchemy==2

0 comments on commit f5af4da

Please sign in to comment.