From 58001187c136ef3310004ece5f60f7591f7e4506 Mon Sep 17 00:00:00 2001 From: dwreeves Date: Sat, 3 Dec 2022 20:37:11 -0500 Subject: [PATCH 1/2] fix flask-sqlalchemy regression --- .github/workflows/main.yml | 3 +++ pytest_flask_sqlalchemy/fixtures.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1aec67e..01d694e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,7 @@ jobs: matrix: python: [3.7.x, 3.8.x, 3.9.x, 3.10.x] sqlalchemy: [1.2.*, 1.3.*, 1.4.*] + flask_sqlalchemy: [2.*, 3.*] services: postgres: image: postgres:11 @@ -36,7 +37,9 @@ jobs: pip install --upgrade pip pip install -e .[tests] pip install --upgrade sqlalchemy=="${SQLALCHEMY_VERSION}" + pip install --upgrade flask-sqlalchemy=="${FLASK_SQLALCHEMY_VERSION}" pytest env: TEST_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/pytest_test SQLALCHEMY_VERSION: ${{ matrix.sqlalchemy }} + FLASK_SQLALCHEMY_VERSION: ${{ matrix.flask_sqlalchemy }} diff --git a/pytest_flask_sqlalchemy/fixtures.py b/pytest_flask_sqlalchemy/fixtures.py index 0396bd6..86a1003 100644 --- a/pytest_flask_sqlalchemy/fixtures.py +++ b/pytest_flask_sqlalchemy/fixtures.py @@ -35,7 +35,13 @@ def _transaction(request, _db, mocker): # when specifying a `bind` option, or else Flask-SQLAlchemy won't scope # the connection properly options = dict(bind=connection, binds={}) - session = _db.create_scoped_session(options=options) + try: + create_scoped_session = _db.create_scoped_session + except AttributeError: + # For Flask-SQLAlchemy version > 3.0 + create_scoped_session = _db._make_scoped_session + + session = create_scoped_session(options=options) # Make sure the session, connection, and transaction can't be closed by accident in # the codebase From c6cc8203ad8cb8deca98fb81da770a0ddde65e50 Mon Sep 17 00:00:00 2001 From: dwreeves Date: Sat, 25 Feb 2023 13:19:57 -0500 Subject: [PATCH 2/2] fix-regression-flask-sqlalchemy-3.0 --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01d694e..4ecd7c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,8 @@ jobs: matrix: python: [3.7.x, 3.8.x, 3.9.x, 3.10.x] sqlalchemy: [1.2.*, 1.3.*, 1.4.*] - flask_sqlalchemy: [2.*, 3.*] + flask_sqlalchemy: [2.*] + # flask_sqlalchemy: [2.*, 3.*] services: postgres: image: postgres:11