fix(deps): upgrade to sqlalchemy version 2

Bump sqlalchemy to version 2.0.22

There are quite some changes that happened with v2.
We are currently relying on the "auto-commit" feature which was removed.
For the moment we can use a wrapper class to mimic the auto-commit
behavior allowing us to move to v2.

Ultimately, the (db) session management needs some overhaul though.

Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
moson-mo 2023-06-30 11:05:18 +02:00 committed by moson
parent 27c51430fb
commit db004d5ebd
No known key found for this signature in database
GPG key ID: 4A4760AB4EE15296
12 changed files with 182 additions and 160 deletions

View file

@ -2,6 +2,17 @@
DRIVERS = {"mysql": "mysql+mysqldb"}
class Committer:
def __init__(self, session):
self.session = session
def __enter__(self):
pass
def __exit__(self, *args):
self.session.commit()
def make_random_value(table: str, column: str, length: int):
"""Generate a unique, random value for a string column in a table.
@ -76,9 +87,7 @@ def get_session(engine=None):
if not engine: # pragma: no cover
engine = get_engine()
Session = scoped_session(
sessionmaker(autocommit=True, autoflush=False, bind=engine)
)
Session = scoped_session(sessionmaker(autoflush=False, bind=engine))
_sessions[dbname] = Session()
return _sessions.get(dbname)
@ -158,7 +167,7 @@ def add(model):
def begin():
"""Begin an SQLAlchemy SessionTransaction."""
return get_session().begin()
return Committer(get_session())
def retry_deadlock(func):
@ -217,7 +226,7 @@ def get_sqlalchemy_url():
parts = sqlalchemy.__version__.split(".")
major = int(parts[0])
minor = int(parts[1])
if major == 1 and minor >= 4: # pragma: no cover
if (major == 1 and minor >= 4) or (major == 2): # pragma: no cover
constructor = URL.create
aur_db_backend = aurweb.config.get("database", "backend")