.. changelog::
:version: 0.9.9
+ .. change::
+ :tags: bug, engine
+ :tickets: 3302
+
+ Fixed bug in :class:`.Connection` and pool where the
+ :meth:`.Connection.invalidate` method, or an invalidation due
+ to a database disconnect, would fail if the
+ ``isolation_level`` parameter had been used with
+ :meth:`.Connection.execution_options`; the "finalizer" that resets
+ the isolation level would be called on the no longer opened connection.
+
.. change::
:tags: feature, orm
:tickets: 3296
transaction has been started with :meth:`.Connection.begin`
or similar.
+ .. note:: The ``isolation_level`` execution option is implicitly
+ reset if the :class:`.Connection` is invalidated, e.g. via
+ the :meth:`.Connection.invalidate` method, or if a
+ disconnection error occurs. The new connection produced after
+ the invalidation will not have the isolation level re-applied
+ to it automatically.
+
.. seealso::
:paramref:`.create_engine.isolation_level`
return self.connection
def __close(self):
+ self.finalize_callback.clear()
self.__pool._close_connection(self.connection)
def __connect(self):
from sqlalchemy.testing.schema import Table, Column
import sqlalchemy as tsa
from sqlalchemy import testing
+from sqlalchemy.testing import mock
from sqlalchemy.testing import engines
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.engines import testing_engine
[[call()], []]
)
+ def test_invalidate_dont_call_finalizer(self):
+ conn = self.db.connect()
+ finalizer = mock.Mock()
+ conn.connection._connection_record.\
+ finalize_callback.append(finalizer)
+ conn.invalidate()
+ assert conn.invalidated
+ eq_(finalizer.call_count, 0)
+
def test_conn_reusable(self):
conn = self.db.connect()
eng.connect
)
+ def test_connection_invalidated(self):
+ eng = testing_engine()
+ conn = eng.connect()
+ c2 = conn.execution_options(
+ isolation_level=self._non_default_isolation_level())
+ c2.invalidate()
+ c2.connection
+
+ # TODO: do we want to rebuild the previous isolation?
+ # for now, this is current behavior so we will leave it.
+ eq_(c2.get_isolation_level(), self._default_isolation_level())
+
def test_per_connection(self):
from sqlalchemy.pool import QueuePool
eng = testing_engine(