From f5af4dad292b50ee6ee17afba2bbeb93ab2b5625 Mon Sep 17 00:00:00 2001 From: Jonathan Wu Date: Sun, 17 Dec 2023 23:03:19 -0500 Subject: [PATCH] Permanent fix for cs50 SQL bug --- src/db.py | 20 +------------------- src/requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/db.py b/src/db.py index bfd6e04..909629b 100644 --- a/src/db.py +++ b/src/db.py @@ -1,26 +1,8 @@ -from cs50 import SQL as cs50_SQL +from cs50 import SQL import sqlalchemy 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 diff --git a/src/requirements.txt b/src/requirements.txt index e4e996c..9c95112 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -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