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 fixture incompatibility with Flask-SQLAlchemy #100

Open
ntarocco opened this issue Apr 17, 2023 · 2 comments
Open

db fixture incompatibility with Flask-SQLAlchemy #100

ntarocco opened this issue Apr 17, 2023 · 2 comments
Assignees
Labels

Comments

@ntarocco
Copy link
Contributor

Flask-SQLAlchemy v3 introduced breaking changing related to scoped and nested session.
The following PRs attempted to solve the issue:

While local tests were passing, tests in modules using pytest-invenio started failing.

Explanation

The db fixture has scope: function: it creates a nested session, which starts a transaction using a SAVEPOINT. When the test completes, the DB state is rolled back to the previous clean state. See doc here and how to use it in the tests here.

The new version of Flask-SQLAlchemy v3 removes the previously public method create_scoped_session and changes how the DB session are bound to the Flask context. This breaks the fixture.

Note: what is unclear is why the local tests pass (see test_db test), while tests in other modules using that fixtures fail.

Relevant references:

@monotasker
Copy link

Is there any fix for this in the works? When I'm running v. 2.1.2, I get an error when the db fixture tries to call database.create_scoped_session(options=options)? I got rid of the error by changing this to call database._make_scoped_session(options=options). But I don't know whether the resulting fixture will work as expected.

@ntarocco
Copy link
Contributor Author

@utnapischtim is working on that to find a solution. At the moment, no fix available yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants