Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flask-sqlalchemy regression #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +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.*]
# flask_sqlalchemy: [2.*, 3.*]
services:
postgres:
image: postgres:11
Expand All @@ -36,7 +38,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 }}
8 changes: 7 additions & 1 deletion pytest_flask_sqlalchemy/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down