-
Notifications
You must be signed in to change notification settings - Fork 45
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
SQLAlchemy 1.4.x: RootTransaction object cannot serve as stash storage for original method references #46
Comments
Here's one I just had to deal with. Whenever I use the
I've had to roll-back to SQLAlchemy v.1.3.24 |
Is anyone working on a fix? |
@jace we quite successfully dropped this package and we wrote our own fixture. this is the code, you might need to adapt it slightly for your needs @pytest.fixture(autouse=True)
def enable_transactional_tests(db, connection):
transaction = connection.begin()
db.session = db.create_scoped_session(options={"bind": connection, "binds": {}})
db.session.begin_nested()
# for handling tests that actually call "session.rollback()"
# https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#joining-a-session-into-an-external-transaction-such-as-for-test-suites
@event.listens_for(db.session, "after_transaction_end")
def restart_savepoint(session, transaction_in):
if transaction_in.nested and not transaction_in._parent.nested:
session.expire_all()
session.begin_nested()
yield
db.session.close()
transaction.rollback() where the @pytest.fixture(scope="session")
def connection(db):
return db.engine.connect() |
Deal breaker for me as well. |
@itajaja That snippet looks pretty great. Perhaps this is verging off-topic a little, but do you have any plans to wrap that into a |
@jayaddison absolutely, feel free to package it up! it's small enough that we just put it in our internal utilities library, but make it an OSS package if you want :) |
Thanks @itajaja. I'm puzzling over this a little bit. One of the features that In other words, even if the test-covered application code runs some of its' own database modifications, Currently I think your code will rollback any database modifications made using the |
not sure I follow, could you give me a more concrete example as to when the |
@itajaja Sure - see openculinary/backend@61bf1ae and the associated branch for an example of me testing this out. On that branch I've been running the tests with
Here's the relevant test code, for reference: https://github.com/openculinary/backend/blob/61bf1ae6f40e4fbd3468f27b7d208e278886806a/tests/models/test_url.py#L43-L69 From some debugging, it seems like the mocked (in comparison, |
what if instead of using create_db, you |
@itajaja 🤦 Of course, yep - that would make a lot more sense, thank you. That has most of the tests passing, and the one remaining failure does not appear database-related. Great. I'll start to look into what's required (and/or possible) in terms of packaging the fixture up as a Python package soon, and I'll include credit and authorship details for the code. |
great!! |
sqlalchemy 1.4 support was added in #51, so I think this can be resolved 🎉 |
The 1.4 major release of
sqlalchemy
seems to introduce some interface changes thatpytest-flask-sqlalchemy
1.0.2 has trouble handling.In particular one case is that
pytest-flask-sqlalchemy
will attempt to store a transaction's originalrollback
method in a temporary / ephemeralforce_rollback
property, but the currentsqlalchemy
1.4.0 release seems incompatible with this -- I think because theRootTransaction
class defines an explicit list ofslots
available on the object.This issue might be a one-off, or it could be part of a larger category of
sqlalchemy
1.4 compatibility concerns.The text was updated successfully, but these errors were encountered: