Merge "Add _wrap_db_error() support to SessionTransaction.commit()" into stable/icehouse

This commit is contained in:
Jenkins 2014-11-08 11:38:13 +00:00 committed by Gerrit Code Review
commit 3efc858d67
1 changed files with 19 additions and 0 deletions

View File

@ -700,6 +700,25 @@ class Session(sqlalchemy.orm.session.Session):
def commit(self, *args, **kwargs):
return super(Session, self).commit(*args, **kwargs)
def begin(self, **kw):
trans = super(Session, self).begin(**kw)
trans.__class__ = SessionTransactionWrapper
return trans
class SessionTransactionWrapper(sqlalchemy.orm.session.SessionTransaction):
@property
def bind(self):
return self.session.bind
@_wrap_db_error
def commit(self, *args, **kwargs):
return super(SessionTransactionWrapper, self).commit(*args, **kwargs)
@_wrap_db_error
def rollback(self, *args, **kwargs):
return super(SessionTransactionWrapper, self).rollback(*args, **kwargs)
def get_maker(engine, autocommit=True, expire_on_commit=False):
"""Return a SQLAlchemy sessionmaker using the given engine."""