All pastes #945294 Raw Edit

Someone

public text v1 · immutable
·published 2008-03-16 20:44 UTC
rendered paste body
Session = scoped_session(sessionmaker(autoflush=True, transactional=True))
engine = create_engine('mysql://')

# start request

django_connection = get_django_DBAPI_connection_from_wherever()

sa_connection = sqlalchemy.engine.base.Connection(engine=engine, connection=django_connection, **possibly_other_stuff)

# preexisting transaction ?  create a "fake" Transaction
trans = sqlalchemy.engine.base.Transaction(sa_connection)
sa_connection._Connection__transaction = trans  # we'd need to give you an API for this

# set up thread-local Session bound to Connection
Session(bind=sa_connection)

try:
# do request
finally:
   Session.remove()