.. changelog::
:version: 0.8.3
+ :tickets: 2776
+
+ Dialect.initialize() is not called a second time if an :class:`.Engine`
+ is recreated, due to a disconnect error. This fixes a particular
+ issue in the Oracle 8 dialect, but in general the dialect.initialize()
+ phase should only be once per dialect.
+
.. change::
:tags: feature, sql
:tickets: 722
event.listen(pool, 'first_connect', on_connect)
event.listen(pool, 'connect', on_connect)
+ @util.only_once
def first_connect(dbapi_connection, connection_record):
c = base.Connection(engine, connection=dbapi_connection)
duck_type_collection, assert_arg_type, symbol, dictlike_iteritems,\
classproperty, set_creation_order, warn_exception, warn, NoneType,\
constructor_copy, methods_equivalent, chop_traceback, asint,\
- generic_repr, counter, PluginLoader, hybridmethod, safe_reraise
+ generic_repr, counter, PluginLoader, hybridmethod, safe_reraise,\
+ only_once
from .deprecations import warn_deprecated, warn_pending_deprecation, \
deprecated, pending_deprecation
_UNITTEST_RE = re.compile(r'unit(?:2|test2?/)')
+def only_once(fn):
+ """Decorate the given function to be a no-op after it is called exactly
+ once."""
+
+ once = [fn]
+ def go(*arg, **kw):
+ if once:
+ once_fn = once.pop()
+ return once_fn(*arg, **kw)
+
+ return update_wrapper(go, fn)
+
+
+
def chop_traceback(tb, exclude_prefix=_UNITTEST_RE, exclude_suffix=_SQLA_RE):
"""Chop extraneous lines off beginning and end of a traceback.
list, result
)
+ def test_dialect_initialize_once(self):
+ from sqlalchemy.engine.base import Engine
+ from sqlalchemy.engine.url import URL
+ from sqlalchemy.engine.default import DefaultDialect
+ from sqlalchemy.pool import QueuePool
+ dbapi = self.dbapi
+
+ mock_dialect = Mock()
+ class MyURL(URL):
+ def get_dialect(self):
+ return Dialect
+ class Dialect(DefaultDialect):
+ initialize = Mock()
+
+ engine = create_engine(MyURL("foo://"), module=dbapi)
+ c1 = engine.connect()
+ engine.dispose()
+ c2 = engine.connect()
+ eq_(Dialect.initialize.call_count, 1)
+
+
+
class CursorErrTest(fixtures.TestBase):
def setup(self):
# raises a DBAPIError, not an AttributeError
assert_raises(exc.DBAPIError, engine.connect)
- # dispose connections so we get a new one on
- # next go
- engine.dispose()
+ @testing.skip_if(
+ [lambda: util.py3k, "oracle+cx_oracle"],
+ "Crashes on py3k+cx_oracle")
+ def test_explode_in_initializer_disconnect(self):
+ engine = engines.testing_engine()
+ def broken_initialize(connection):
+ connection.execute("select fake_stuff from _fake_table")
+
+ engine.dialect.initialize = broken_initialize
p1 = engine.pool