Skip to content

Commit 8841ece

Browse files
committed
Upgrade SQLAlchemy to version 2.0
1 parent 2a434da commit 8841ece

27 files changed

+234
-197
lines changed

web/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
Authlib<2
88
requests<3 # Required by Authlib. Not installed automatically for some reason.
99
lxml<6
10-
sqlalchemy<2
11-
alembic<2
10+
sqlalchemy~=2.0
11+
alembic~=1.5
1212
portalocker<4
1313
psutil<8
1414
multiprocess<0.71

web/requirements_py/db_pg8000/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
lxml<6
2-
sqlalchemy<2
3-
alembic<2
4-
pg8000<=1.31.4
2+
sqlalchemy~=2.0
3+
alembic~=1.5
4+
pg8000~=1.31
55
psutil<8
66
portalocker<4
77

web/requirements_py/db_psycopg2/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
lxml<6
2-
sqlalchemy<2
3-
alembic<2
4-
psycopg2-binary<=2.9.10
2+
sqlalchemy~=2.0
3+
alembic~=1.5
4+
psycopg2-binary~=2.9
55
psutil<8
66
portalocker<4
77

web/requirements_py/dev/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pycodestyle<=2.12.0
2-
psycopg2-binary<=2.9.10
3-
pg8000<=1.31.4
2+
psycopg2-binary~=2.9
3+
pg8000~=1.31
44
pylint<3.3
55
pytest<=7.3.1
66
mkdocs<=1.5.3

web/server/codechecker_server/api/mass_store_run.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ def __init__(self,
412412
self.user_name = user_name
413413

414414
with DBSession(self._config_db) as session:
415-
product: Optional[Product] = session.query(Product) \
416-
.get(product_id)
415+
product: Optional[Product] = session.get(Product, product_id)
417416
if not product:
418417
raise KeyError(f"No product with ID '{product_id}'")
419418

@@ -576,8 +575,8 @@ def _implementation(self, tm: TaskManager):
576575
raise
577576

578577
with DBSession(tm.configuration_database_session_factory) as session:
579-
db_product: Optional[Product] = session.query(Product) \
580-
.get(self._product_id)
578+
db_product: Optional[Product] = \
579+
session.get(Product, self._product_id)
581580
if not db_product:
582581
raise KeyError(f"No product with ID '{self._product_id}'")
583582

@@ -668,7 +667,7 @@ def __init__(self,
668667
str, Tuple[Report, Union[DBReport, int]]] = {}
669668

670669
with DBSession(config_db) as session:
671-
product = session.query(Product).get(self.__product.id)
670+
product = session.get(Product, self.__product.id)
672671
self.__report_limit = product.report_limit
673672

674673
def __store_source_files(
@@ -793,7 +792,7 @@ def __add_file_content(
793792
hasher.update(source_file_content)
794793
content_hash = hasher.hexdigest()
795794

796-
file_content = session.query(FileContent).get(content_hash)
795+
file_content = session.get(FileContent, content_hash)
797796
if not file_content:
798797
if not source_file_content:
799798
source_file_content = get_file_content(source_file_name)
@@ -1587,7 +1586,7 @@ def finish_checker_run(
15871586
""" Finish the storage of the given run. """
15881587
try:
15891588
LOG.debug("Finishing checker run")
1590-
run = session.query(Run).get(run_id)
1589+
run = session.get(Run, run_id)
15911590
if not run:
15921591
return False
15931592

web/server/codechecker_server/api/product_server.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import random
1515

16+
from sqlalchemy import text
1617
from sqlalchemy.sql.expression import and_
1718

1819
from sqlalchemy import create_engine, exc
@@ -244,7 +245,7 @@ def getCurrentProduct(self):
244245
msg)
245246

246247
with DBSession(self.__session) as session:
247-
prod = session.query(Product).get(self.__product.id)
248+
prod = session.get(Product, self.__product.id)
248249

249250
if not prod:
250251
msg = "The product requested has been disconnected from the " \
@@ -270,7 +271,7 @@ def getProductConfiguration(self, product_id):
270271
], {'productID': product_id})
271272

272273
with DBSession(self.__session) as session:
273-
product = session.query(Product).get(product_id)
274+
product = session.get(Product, product_id)
274275
if product is None:
275276
msg = f"Product with ID {product_id} does not exist!"
276277
LOG.error(msg)
@@ -354,7 +355,7 @@ def __create_product_database(self, product):
354355
db_pass = convert.from_b64(product_info.password_b64)
355356
db_name = product_info.database
356357

357-
engine_url = URL(
358+
engine_url = URL.create(
358359
drivername=db_engine,
359360
username=db_user,
360361
password=db_pass,
@@ -365,9 +366,9 @@ def __create_product_database(self, product):
365366
engine = create_engine(engine_url)
366367
try:
367368
with engine.connect() as conn:
368-
conn.execute("commit")
369+
conn.execute(text("commit"))
369370
LOG.info("Creating database '%s'", db_name)
370-
conn.execute(f"CREATE DATABASE {db_name}")
371+
conn.execute(text(f"CREATE DATABASE {db_name}"))
371372
conn.close()
372373
except exc.ProgrammingError as e:
373374
LOG.error("ProgrammingError occurred: %s", str(e))
@@ -555,7 +556,7 @@ def editProduct(self, product_id, new_config):
555556
new_configuration.
556557
"""
557558
with DBSession(self.__session) as session:
558-
product = session.query(Product).get(product_id)
559+
product = session.get(Product, product_id)
559560
if product is None:
560561
msg = f"Product with ID {product_id} does not exist!"
561562
LOG.error(msg)
@@ -735,7 +736,7 @@ def editProduct(self, product_id, new_config):
735736
LOG.info("Product configuration edited and saved successfully.")
736737

737738
if product_needs_reconnect:
738-
product = session.query(Product).get(product_id)
739+
product = session.get(Product, product_id)
739740
LOG.info("Product change requires database reconnection...")
740741

741742
LOG.debug("Disconnecting...")
@@ -762,7 +763,7 @@ def removeProduct(self, product_id):
762763
self.__require_permission([permissions.SUPERUSER])
763764

764765
with DBSession(self.__session) as session:
765-
product = session.query(Product).get(product_id)
766+
product = session.get(Product, product_id)
766767
if product is None:
767768
msg = f"Product with ID {product_id} does not exist!"
768769
LOG.error(msg)

0 commit comments

Comments
 (0)