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

db: upgrade flask-sqlalchemy #97

Merged
merged 1 commit into from
Apr 13, 2023
Merged
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
19 changes: 5 additions & 14 deletions pytest_invenio/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,22 +488,13 @@ def db(database):

connection = database.engine.connect()
transaction = connection.begin()
old_session = database.session

# Create a new session and assign it to the current db session.
# The new session is scoped and bound to the `connection`.
options = dict(bind=connection, binds={})
session = database.create_scoped_session(options=options)

session.begin_nested()

# `session` is actually a scoped_session. For the `after_transaction_end`
# event, we need a session instance to listen for, hence the `session()`
# call.
@sa.event.listens_for(session(), "after_transaction_end")
def restart_savepoint(sess, trans):
if trans.nested and not trans._parent.nested:
session.expire_all()
session.begin_nested()

old_session = database.session
session_factory = sa.orm.sessionmaker(**options)
session = sa.orm.scoped_session(session_factory)
database.session = session

yield database
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ install_requires =
tests =
pytest-black>=0.3.0
invenio-celery>=1.2.4,<2.0.0
invenio-db>=1.0.12,<2.0.0
invenio-db>=1.1.0,<2.0.0
invenio-files-rest>=1.3.2,<2.0.0
invenio-mail>=1.0.2,<2.0.0
invenio-search>=2.1.0,<3.0.0
Expand Down
8 changes: 4 additions & 4 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ def test_db(conftest_testdir):
"""Test database creation and initialization."""
conftest_testdir.makepyfile(
"""
from invenio_db import db
from invenio_db import db as _db
class UserA(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
class UserA(_db.Model):
id = _db.Column(_db.Integer, primary_key=True)
username = _db.Column(_db.String(80), unique=True)
def test_db1(db):
assert UserA.query.count() == 0
Expand Down