From b8c60f8214c3f8272948d325c1bfc1b93755117a Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Mon, 30 Aug 2021 10:23:01 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20UPGRADE:=20psycopg2=20?= =?UTF-8?q?allow=20v2.9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed in https://github.com/aiidateam/pgsu/pull/27 fixes #5002 --- environment.yml | 4 ++-- pyproject.toml | 4 ++-- requirements/requirements-py-3.10.txt | 2 +- requirements/requirements-py-3.8.txt | 2 +- requirements/requirements-py-3.9.txt | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/environment.yml b/environment.yml index e955049449..6728069ab4 100644 --- a/environment.yml +++ b/environment.yml @@ -24,9 +24,9 @@ dependencies: - pamqp~=2.3 - paramiko>=2.7.2,~=2.7 - plumpy~=0.20.0 -- pgsu~=0.2.0 +- pgsu~=0.2.1 - psutil~=5.6 -- psycopg2-binary~=2.8.3 +- psycopg2-binary~=2.8 - python-dateutil~=2.8 - pytz~=2021.1 - pyyaml~=5.4 diff --git a/pyproject.toml b/pyproject.toml index bad767ddbc..1e87bb6e16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,9 +42,9 @@ dependencies = [ "pamqp~=2.3", "paramiko~=2.7,>=2.7.2", "plumpy~=0.20.0", - "pgsu~=0.2.0", + "pgsu~=0.2.1", "psutil~=5.6", - "psycopg2-binary~=2.8.3", + "psycopg2-binary~=2.8", "python-dateutil~=2.8", "pytz~=2021.1", "pyyaml~=5.4", diff --git a/requirements/requirements-py-3.10.txt b/requirements/requirements-py-3.10.txt index 1f8ed25291..64c638237f 100644 --- a/requirements/requirements-py-3.10.txt +++ b/requirements/requirements-py-3.10.txt @@ -94,7 +94,7 @@ plumpy==0.20.0 prometheus-client==0.12.0 prompt-toolkit==3.0.23 psutil==5.8.0 -psycopg2-binary==2.8.6 +psycopg2-binary==2.9.1 ptyprocess==0.7.0 py==1.11.0 py-cpuinfo==8.0.0 diff --git a/requirements/requirements-py-3.8.txt b/requirements/requirements-py-3.8.txt index f5c1f21684..31b8e365e2 100644 --- a/requirements/requirements-py-3.8.txt +++ b/requirements/requirements-py-3.8.txt @@ -95,7 +95,7 @@ plumpy==0.20.0 prometheus-client==0.12.0 prompt-toolkit==3.0.23 psutil==5.8.0 -psycopg2-binary==2.8.6 +psycopg2-binary==2.9.1 ptyprocess==0.7.0 py==1.11.0 py-cpuinfo==8.0.0 diff --git a/requirements/requirements-py-3.9.txt b/requirements/requirements-py-3.9.txt index c86749a743..7e1ceb58ce 100644 --- a/requirements/requirements-py-3.9.txt +++ b/requirements/requirements-py-3.9.txt @@ -94,7 +94,7 @@ plumpy==0.20.0 prometheus-client==0.12.0 prompt-toolkit==3.0.23 psutil==5.8.0 -psycopg2-binary==2.8.6 +psycopg2-binary==2.9.1 ptyprocess==0.7.0 py==1.11.0 py-cpuinfo==8.0.0 From 6ad79a05787fcc3dcc571e7b91bee7c3bfb5d773 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Wed, 16 Feb 2022 18:50:39 +0100 Subject: [PATCH 2/3] close psycop2g connections --- .../aiida_sqlalchemy/migrations/conftest.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/backends/aiida_sqlalchemy/migrations/conftest.py b/tests/backends/aiida_sqlalchemy/migrations/conftest.py index e93d83977e..a267381f92 100644 --- a/tests/backends/aiida_sqlalchemy/migrations/conftest.py +++ b/tests/backends/aiida_sqlalchemy/migrations/conftest.py @@ -35,10 +35,15 @@ def uninitialised_profile(empty_pg_cluster: PGTest, tmp_path): # pylint: disabl database_name = f'test_{uuid4().hex}' - with psycopg2.connect(**empty_pg_cluster.dsn) as conn: + conn = None + try: + conn = psycopg2.connect(**empty_pg_cluster.dsn) conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) with conn.cursor() as cursor: cursor.execute(f"CREATE DATABASE {database_name} ENCODING 'utf8';") + finally: + if conn: + conn.close() yield Profile( 'test_migrate', { @@ -61,7 +66,9 @@ def uninitialised_profile(empty_pg_cluster: PGTest, tmp_path): # pylint: disabl } ) - with psycopg2.connect(**empty_pg_cluster.dsn) as conn: + conn = None + try: + conn = psycopg2.connect(**empty_pg_cluster.dsn) conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) with conn.cursor() as cursor: # note after postgresql 13 you can use 'DROP DATABASE name WITH (FORCE)' @@ -69,7 +76,9 @@ def uninitialised_profile(empty_pg_cluster: PGTest, tmp_path): # pylint: disabl # see: https://dba.stackexchange.com/questions/11893/force-drop-db-while-others-may-be-connected cursor.execute(f"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '{database_name}';") cursor.execute(f'DROP DATABASE {database_name};') - + finally: + if conn: + conn.close() @pytest.fixture() def perform_migrations(uninitialised_profile): # pylint: disable=redefined-outer-name From 0f85a6c03776e69246811c700af5c276ca8eae8e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 16 Feb 2022 17:52:53 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/backends/aiida_sqlalchemy/migrations/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/backends/aiida_sqlalchemy/migrations/conftest.py b/tests/backends/aiida_sqlalchemy/migrations/conftest.py index a267381f92..48b45ffcac 100644 --- a/tests/backends/aiida_sqlalchemy/migrations/conftest.py +++ b/tests/backends/aiida_sqlalchemy/migrations/conftest.py @@ -80,6 +80,7 @@ def uninitialised_profile(empty_pg_cluster: PGTest, tmp_path): # pylint: disabl if conn: conn.close() + @pytest.fixture() def perform_migrations(uninitialised_profile): # pylint: disable=redefined-outer-name """A fixture to setup a database for migration tests."""