From a3255908c1c4b43000ff84ee7da6d95273051aaf Mon Sep 17 00:00:00 2001 From: Ben Clifford Date: Mon, 6 Jan 2025 18:45:20 +0000 Subject: [PATCH] Upgrade SQLAlchemy to version 2 (#3734) This is part of supporting Python 3.13 (PR #3646), as a prereq to upgrading pandas. # Changed Behaviour Development environments (which have the requirements in `test-requirements.txt` installed) will break and need `pip uninstall sqlalchemy2-stubs` - sqlalchemy packaging does not express a negative/removal requirement against that transitional package. non-parsl user code which happens to use the parsl-installed sqlalchemy might break - for example, see API changes in the test suite in this PR ## Type of change - Code maintenance/cleanup --- parsl/monitoring/db_manager.py | 2 +- parsl/tests/test_monitoring/test_app_names.py | 4 ++-- parsl/tests/test_monitoring/test_stdouterr.py | 4 ++-- setup.py | 4 +++- test-requirements.txt | 3 +-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/parsl/monitoring/db_manager.py b/parsl/monitoring/db_manager.py index 8c1d76dbc6..af52944021 100644 --- a/parsl/monitoring/db_manager.py +++ b/parsl/monitoring/db_manager.py @@ -78,7 +78,7 @@ def __init__(self, def _get_mapper(self, table_obj: Table) -> Mapper: all_mappers: Set[Mapper] = set() - for mapper_registry in mapperlib._all_registries(): # type: ignore[attr-defined] + for mapper_registry in mapperlib._all_registries(): all_mappers.update(mapper_registry.mappers) mapper_gen = ( mapper for mapper in all_mappers diff --git a/parsl/tests/test_monitoring/test_app_names.py b/parsl/tests/test_monitoring/test_app_names.py index 1c3b6fef11..ad21d47147 100644 --- a/parsl/tests/test_monitoring/test_app_names.py +++ b/parsl/tests/test_monitoring/test_app_names.py @@ -67,7 +67,7 @@ def test_app_name(get_app, expected_name, expected_result, tmpd_cwd): with engine.begin() as connection: def count_rows(table: str): - result = connection.execute(f"SELECT COUNT(*) FROM {table}") + result = connection.execute(sqlalchemy.text(f"SELECT COUNT(*) FROM {table}")) (c, ) = result.first() return c @@ -81,6 +81,6 @@ def count_rows(table: str): assert count_rows("try") == 1 # ... and has the expected name. - result = connection.execute("SELECT task_func_name FROM task") + result = connection.execute(sqlalchemy.text("SELECT task_func_name FROM task")) (c, ) = result.first() assert c == expected_name diff --git a/parsl/tests/test_monitoring/test_stdouterr.py b/parsl/tests/test_monitoring/test_stdouterr.py index 8e1935045f..982525b7e9 100644 --- a/parsl/tests/test_monitoring/test_stdouterr.py +++ b/parsl/tests/test_monitoring/test_stdouterr.py @@ -106,7 +106,7 @@ def test_stdstream_to_monitoring(stdx, expected_stdx, stream, tmpd_cwd, caplog): with engine.begin() as connection: def count_rows(table: str): - result = connection.execute(f"SELECT COUNT(*) FROM {table}") + result = connection.execute(sqlalchemy.text(f"SELECT COUNT(*) FROM {table}")) (c, ) = result.first() return c @@ -120,7 +120,7 @@ def count_rows(table: str): assert count_rows("try") == 1 # ... and has the expected name. - result = connection.execute(f"SELECT task_{stream} FROM task") + result = connection.execute(sqlalchemy.text(f"SELECT task_{stream} FROM task")) (c, ) = result.first() if isinstance(expected_stdx, str): diff --git a/setup.py b/setup.py index f5aadb1e2e..1511649845 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,9 @@ extras_require = { 'monitoring' : [ - 'sqlalchemy>=1.4,<2' + # sqlalchemy does not use semantic versioning. + # see https://github.com/sqlalchemy/sqlalchemy/discussions/11391#discussioncomment-9472033 + 'sqlalchemy>=2,<2.1' ], 'visualization' : [ # this pydot bound is copied from networkx's pyproject.toml, diff --git a/test-requirements.txt b/test-requirements.txt index 82ec5172c2..2b4d81a6dd 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -14,8 +14,7 @@ mpi4py # sqlalchemy is needed for typechecking, so it's here # as well as at runtime for optional monitoring execution # (where it's specified in setup.py) -sqlalchemy>=1.4,<2 -sqlalchemy2-stubs +sqlalchemy>=2,<2.1 Sphinx==4.5.0 twine