diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-09-03 17:57:20 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-09-03 17:57:20 -0400 |
commit | 33b70a1f0259dd5e4acd2cb78c9a5ab6254cf9ce (patch) | |
tree | 08430231aa8f6d1d84487212ee2c43bc5df7a3cd /lib/sqlalchemy/engine/base.py | |
parent | 47f56ac4990c7c3e6a020a837e91e39f41adf39e (diff) | |
parent | 6e83926657057c97239bef114e640f2b102be02c (diff) | |
download | sqlalchemy-33b70a1f0259dd5e4acd2cb78c9a5ab6254cf9ce.tar.gz |
merge from tip
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 70ad01914..a02e90aba 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -911,6 +911,14 @@ class Connection(Connectable): raise exc.ResourceClosedError("This Connection is closed") @property + def _connection_is_valid(self): + # use getattr() for is_valid to support exceptions raised in + # dialect initializer, where the connection is not wrapped in + # _ConnectionFairy + + return getattr(self.__connection, 'is_valid', False) + + @property def info(self): """A collection of per-DB-API connection instance properties.""" @@ -954,15 +962,18 @@ class Connection(Connectable): operations in a non-transactional state. """ - + if self.invalidated: + return + if self.closed: raise exc.ResourceClosedError("This Connection is closed") - if self.__connection.is_valid: + if self._connection_is_valid: self.__connection.invalidate(exception) del self.__connection self.__invalid = True - + + def detach(self): """Detach the underlying DB-API connection from its connection pool. @@ -1055,11 +1066,8 @@ class Connection(Connectable): raise def _rollback_impl(self): - # use getattr() for is_valid to support exceptions raised in - # dialect initializer, - # where we do not yet have the pool wrappers plugged in if not self.closed and not self.invalidated and \ - getattr(self.__connection, 'is_valid', False): + self._connection_is_valid: if self._echo: self.engine.logger.info("ROLLBACK") try: @@ -1085,37 +1093,37 @@ class Connection(Connectable): if name is None: self.__savepoint_seq += 1 name = 'sa_savepoint_%s' % self.__savepoint_seq - if self.__connection.is_valid: + if self._connection_is_valid: self.engine.dialect.do_savepoint(self, name) return name def _rollback_to_savepoint_impl(self, name, context): - if self.__connection.is_valid: + if self._connection_is_valid: self.engine.dialect.do_rollback_to_savepoint(self, name) self.__transaction = context def _release_savepoint_impl(self, name, context): - if self.__connection.is_valid: + if self._connection_is_valid: self.engine.dialect.do_release_savepoint(self, name) self.__transaction = context def _begin_twophase_impl(self, xid): - if self.__connection.is_valid: + if self._connection_is_valid: self.engine.dialect.do_begin_twophase(self, xid) def _prepare_twophase_impl(self, xid): - if self.__connection.is_valid: + if self._connection_is_valid: assert isinstance(self.__transaction, TwoPhaseTransaction) self.engine.dialect.do_prepare_twophase(self, xid) def _rollback_twophase_impl(self, xid, is_prepared): - if self.__connection.is_valid: + if self._connection_is_valid: assert isinstance(self.__transaction, TwoPhaseTransaction) self.engine.dialect.do_rollback_twophase(self, xid, is_prepared) self.__transaction = None def _commit_twophase_impl(self, xid, is_prepared): - if self.__connection.is_valid: + if self._connection_is_valid: assert isinstance(self.__transaction, TwoPhaseTransaction) self.engine.dialect.do_commit_twophase(self, xid, is_prepared) self.__transaction = None |