Skip to content

Commit 5800118

Browse files
committed
fix flask-sqlalchemy regression
1 parent 12ad2fb commit 5800118

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
matrix:
1717
python: [3.7.x, 3.8.x, 3.9.x, 3.10.x]
1818
sqlalchemy: [1.2.*, 1.3.*, 1.4.*]
19+
flask_sqlalchemy: [2.*, 3.*]
1920
services:
2021
postgres:
2122
image: postgres:11
@@ -36,7 +37,9 @@ jobs:
3637
pip install --upgrade pip
3738
pip install -e .[tests]
3839
pip install --upgrade sqlalchemy=="${SQLALCHEMY_VERSION}"
40+
pip install --upgrade flask-sqlalchemy=="${FLASK_SQLALCHEMY_VERSION}"
3941
pytest
4042
env:
4143
TEST_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/pytest_test
4244
SQLALCHEMY_VERSION: ${{ matrix.sqlalchemy }}
45+
FLASK_SQLALCHEMY_VERSION: ${{ matrix.flask_sqlalchemy }}

pytest_flask_sqlalchemy/fixtures.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ def _transaction(request, _db, mocker):
3535
# when specifying a `bind` option, or else Flask-SQLAlchemy won't scope
3636
# the connection properly
3737
options = dict(bind=connection, binds={})
38-
session = _db.create_scoped_session(options=options)
38+
try:
39+
create_scoped_session = _db.create_scoped_session
40+
except AttributeError:
41+
# For Flask-SQLAlchemy version > 3.0
42+
create_scoped_session = _db._make_scoped_session
43+
44+
session = create_scoped_session(options=options)
3945

4046
# Make sure the session, connection, and transaction can't be closed by accident in
4147
# the codebase

0 commit comments

Comments
 (0)