Open janbuchar opened 5 years ago
Sorry it took me so long to get to this @Teyras! That seems like a pretty nasty race condition. I'd welcome a PR making this change if you've had some success with it. We'll have to be careful to preserve the remove()
function somewhere, since we use it ourselves to tear down the session:
But we should probably be able to get away with preserving the method the same way we do close()
, commit()
, and rollback()
:
With Flask-SQLAlchemy 2.4.0, SQLAlchemy 1.3.3 and pytest-flask-sqlalchemy 1.0.2, I sometimes (non-deterministically) got
DetachedInstanceError
because the session instantiated in theflask_sqlalchemy.SQLAlchemy
extension already terminated the session (https://github.com/pallets/flask-sqlalchemy/blob/master/flask_sqlalchemy/__init__.py#L849).Adding something like this to
conftest.py
helped.