From d3d1ccd413240f4adda44e25fda2d2c3a86a7ba7 Mon Sep 17 00:00:00 2001 From: Ian Stuart Date: Mon, 10 Jul 2023 09:35:45 +0100 Subject: [PATCH 1/5] update nbgrader version and hide smoketest --- nbexchange/tests/test_smoketest.py | 6 ------ pyproject.toml | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 nbexchange/tests/test_smoketest.py diff --git a/nbexchange/tests/test_smoketest.py b/nbexchange/tests/test_smoketest.py deleted file mode 100644 index da16c7f7..00000000 --- a/nbexchange/tests/test_smoketest.py +++ /dev/null @@ -1,6 +0,0 @@ -import socket - - -def test_smoketest_nbexchange(container): - sock = socket.socket() - sock.connect(("127.0.0.1", container.ports["9000/tcp"][0])) diff --git a/pyproject.toml b/pyproject.toml index d1189a43..00203d68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,8 @@ classifiers = [ dependencies = [ "alembic>=1.6.5", "jupyterhub>=1.4.1", - "nbgrader==0.8.2", # From pypi dated March 28th 2023 + # "nbgrader==0.8.2", # From pypi dated March 28th 2023 + "nbgrader==0.8.4", # From pypi dated 2023-06-16 "psycopg2-binary>=2.8.6", "pyjwt<2", "sentry-sdk==1.14.0", From ffb428acdddd2637c32c1fbbdd44778370f3adfa Mon Sep 17 00:00:00 2001 From: Ian Stuart Date: Mon, 10 Jul 2023 09:47:24 +0100 Subject: [PATCH 2/5] Remove the tests for python 3.8 and 3.9 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8285071e..f041bfd9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.8, 3.9, "3.10", "3.11"] + python-version: ["3.10", "3.11"] steps: - uses: actions/checkout@master - name: Setup Python ${{ matrix.python-version }} From a93dea27ff70117c502909aaa05c1a117f7afaad Mon Sep 17 00:00:00 2001 From: Ian Stuart Date: Mon, 10 Jul 2023 13:52:49 +0100 Subject: [PATCH 3/5] update to sqlalchemy 2.0 --- nbexchange/app.py | 1 + nbexchange/dbutil.py | 14 ++++++++------ nbexchange/models/__init__.py | 4 ++-- pyproject.toml | 3 ++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/nbexchange/app.py b/nbexchange/app.py index 2996d0bf..3f162851 100644 --- a/nbexchange/app.py +++ b/nbexchange/app.py @@ -141,6 +141,7 @@ def init_logging(self): See sqlalchemy.create_engine for details. """ ).tag(config=True) + upgrade_db = Bool( False, help="""Upgrade the database automatically on start. diff --git a/nbexchange/dbutil.py b/nbexchange/dbutil.py index 69e29632..a4980941 100644 --- a/nbexchange/dbutil.py +++ b/nbexchange/dbutil.py @@ -217,7 +217,7 @@ def register_ping_connection(engine): From SQLAlchemy docs on pessimistic disconnect handling: - https://docs.sqlalchemy.org/en/rel_1_1/core/pooling.html#disconnect-handling-pessimistic + https://docs.sqlalchemy.org/en/20/core/pooling.html#custom-legacy-pessimistic-ping """ @event.listens_for(engine, "engine_connect") @@ -236,7 +236,7 @@ def ping_connection(connection, branch): # run a SELECT 1. use a core select() so that # the SELECT of a scalar value without a table is # appropriately formatted for the backend - connection.scalar(select([1])) + connection.scalar(select(1)) except exc.DBAPIError as err: # catch SQLAlchemy's DBAPIError, which is a wrapper # for the DBAPI's exception. It includes a .connection_invalidated @@ -249,7 +249,7 @@ def ping_connection(connection, branch): # itself and establish a new connection. The disconnect detection # here also causes the whole connection pool to be invalidated # so that all stale connections are discarded. - connection.scalar(select([1])) + connection.scalar(select(1)) else: raise finally: @@ -349,13 +349,15 @@ def setup_db(url="sqlite:///:memory:", reset=False, log=None, **kwargs): # is ever created. kwargs.setdefault("poolclass", StaticPool) - engine = create_engine(url, **kwargs) + # From sqlalchemy 2.0, testing pools is now built in + engine = create_engine(url, pool_pre_ping=True, **kwargs) if url.startswith("sqlite"): register_foreign_keys(engine) - # enable pessimistic disconnect handling - register_ping_connection(engine) + # not needed: https://docs.sqlalchemy.org/en/20/core/pooling.html#disconnect-handling-pessimistic + # # enable pessimistic disconnect handling + # register_ping_connection(engine) if reset: Base.metadata.drop_all(engine) diff --git a/nbexchange/models/__init__.py b/nbexchange/models/__init__.py index 2aa0c216..cb7c0590 100644 --- a/nbexchange/models/__init__.py +++ b/nbexchange/models/__init__.py @@ -5,9 +5,9 @@ must be imported below the declaration for `Alembic` autogenerate to work. """ -from sqlalchemy.ext.declarative import declarative_base +import sqlalchemy.orm as orm -Base = declarative_base() +Base = orm.declarative_base() # E402 : module level import not at top of file # F401 : module imported but unused diff --git a/pyproject.toml b/pyproject.toml index 00203d68..4b2ddcc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ classifiers = [ ] # pyjwt limited due to djangorestframework-jwt dependencies +# sqlalchemy spec is the same as nbgrader 0.8.4 dependencies = [ "alembic>=1.6.5", "jupyterhub>=1.4.1", @@ -40,7 +41,7 @@ dependencies = [ "psycopg2-binary>=2.8.6", "pyjwt<2", "sentry-sdk==1.14.0", - "sqlalchemy>=1.4.3", + "sqlalchemy>=1.4,<3", "tornado==6.1", "tornado-prometheus==0.1.1", ] From e3178db34d69508553b99c503762f9aab716a32c Mon Sep 17 00:00:00 2001 From: Ian Stuart Date: Mon, 10 Jul 2023 15:52:12 +0100 Subject: [PATCH 4/5] revert sqlalchemy to allow 1.4.x --- nbexchange/models/__init__.py | 5 +++-- pyproject.toml | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/nbexchange/models/__init__.py b/nbexchange/models/__init__.py index cb7c0590..c62b37a7 100644 --- a/nbexchange/models/__init__.py +++ b/nbexchange/models/__init__.py @@ -5,9 +5,10 @@ must be imported below the declaration for `Alembic` autogenerate to work. """ -import sqlalchemy.orm as orm +# import sqlalchemy.orm as orm +from sqlalchemy.orm import declarative_base -Base = orm.declarative_base() +Base = declarative_base() # E402 : module level import not at top of file # F401 : module imported but unused diff --git a/pyproject.toml b/pyproject.toml index 4b2ddcc3..38b2a0d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,16 +32,14 @@ classifiers = [ ] # pyjwt limited due to djangorestframework-jwt dependencies -# sqlalchemy spec is the same as nbgrader 0.8.4 +# sqlalchemy spec is whatever nbgrader uses! dependencies = [ "alembic>=1.6.5", "jupyterhub>=1.4.1", - # "nbgrader==0.8.2", # From pypi dated March 28th 2023 - "nbgrader==0.8.4", # From pypi dated 2023-06-16 + "nbgrader==0.8.3", # 0.8.4 requires sqlalchemy 2, which breaks Jupyterhub "psycopg2-binary>=2.8.6", "pyjwt<2", "sentry-sdk==1.14.0", - "sqlalchemy>=1.4,<3", "tornado==6.1", "tornado-prometheus==0.1.1", ] From 68b7ca101ab690c8a28c7d179dfe32d3d9d16ecc Mon Sep 17 00:00:00 2001 From: Ian Stuart Date: Mon, 10 Jul 2023 21:33:52 +0100 Subject: [PATCH 5/5] no, need to specify sqlalchemy version --- pyproject.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 38b2a0d2..2180da8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,15 +31,17 @@ classifiers = [ "Intended Audience :: Education", ] +# nbgrader 0.8.4 requires sqlalchemy 2, which breaks Jupyterhub # pyjwt limited due to djangorestframework-jwt dependencies -# sqlalchemy spec is whatever nbgrader uses! +# sqlalchemy spec is whatever nbgrader uses dependencies = [ "alembic>=1.6.5", "jupyterhub>=1.4.1", - "nbgrader==0.8.3", # 0.8.4 requires sqlalchemy 2, which breaks Jupyterhub + "nbgrader==0.8.3", "psycopg2-binary>=2.8.6", "pyjwt<2", "sentry-sdk==1.14.0", + "sqlalchemy>=1.4,<3", "tornado==6.1", "tornado-prometheus==0.1.1", ]