flask-sqlalchemy
                                
                                 flask-sqlalchemy copied to clipboard
                                
                                    flask-sqlalchemy copied to clipboard
                            
                            
                            
                        Binds parameter not respected
#345 is closed without a fix. Now I cannot specify an empty dictionary for the binds parameter in order to use the technique as describe by the SQLAlchemy docs regarding joining a session into an external transaction.
It was closed with a fix, there's a linked commit in that issue.
Hmm, actually, the linked issue rolls back an earlier change. Would you provide a minimal example demonstrating what you need and what doesn't work right now?
I want to specify an empty dictionary for the binds parameter. The example code looks like:
@pytest.yield_fixture()
def db_session(app, db):
    with app.app_context():
        connection = db.engine.connect()
        transaction = connection.begin()
        options = dict(bind=connection, binds={})
        session = db.create_scoped_session(options=options)
        db.session = session
        yield session
        transaction.rollback()
        connection.close()
        session.remove()
I would expect the transaction is rolled back, but it does not. By using the workaround in #345 , it works.
#1087 fixes a bunch of stuff about binds, including making the implementation of get_bind mirror how the base implementation works. I'm not sure if passing binds= as a session option would do anything though, given that Flask-SQAlchemy prefers looking up its configured binds, but it's now possible to customize the session class to do whatever you need by passing session_options={"class_": CustomSession}.