connections are really closed when very
unusual DBAPI errors occur.
+ - metadata.reflect() and reflection.Inspector()
+ had some reliance on GC to close connections
+ which were internally procured, fixed this.
+
- Added explicit check for when Column .name
is assigned as blank string [ticket:2140]
:meth:`Inspector.from_engine`
"""
-
- # ensure initialized
- bind.connect()
-
# this might not be a connection, it could be an engine.
self.bind = bind
self.engine = bind.engine
else:
self.engine = bind
+
+ if self.engine is bind:
+ # if engine, ensure initialized
+ bind.connect().close()
+
self.dialect = self.engine.dialect
self.info_cache = {}
if schema is not None:
reflect_opts['schema'] = schema
- available = util.OrderedSet(bind.engine.table_names(schema,
+ try:
+ available = util.OrderedSet(bind.engine.table_names(schema,
connection=conn))
- if views:
- available.update(
- bind.dialect.get_view_names(conn or bind, schema)
- )
+ if views:
+ available.update(
+ bind.dialect.get_view_names(conn or bind, schema)
+ )
- current = set(self.tables.iterkeys())
+ current = set(self.tables.iterkeys())
- if only is None:
- load = [name for name in available if name not in current]
- elif util.callable(only):
- load = [name for name in available
+ if only is None:
+ load = [name for name in available if name not in current]
+ elif util.callable(only):
+ load = [name for name in available
if name not in current and only(name, self)]
- else:
- missing = [name for name in only if name not in available]
- if missing:
- s = schema and (" schema '%s'" % schema) or ''
- raise exc.InvalidRequestError(
- 'Could not reflect: requested table(s) not available '
- 'in %s%s: (%s)' %
- (bind.engine.url, s, ', '.join(missing)))
- load = [name for name in only if name not in current]
-
- for name in load:
- Table(name, self, **reflect_opts)
+ else:
+ missing = [name for name in only if name not in available]
+ if missing:
+ s = schema and (" schema '%s'" % schema) or ''
+ raise exc.InvalidRequestError(
+ 'Could not reflect: requested table(s) not available '
+ 'in %s%s: (%s)' %
+ (bind.engine.url, s, ', '.join(missing)))
+ load = [name for name in only if name not in current]
+
+ for name in load:
+ Table(name, self, **reflect_opts)
+ finally:
+ if conn is not None:
+ conn.close()
def append_ddl_listener(self, event_name, listener):
"""Append a DDL event listener to this ``MetaData``.
def _server_side_cursors(options, opt_str, value, parser):
db_opts['server_side_cursors'] = True
+def _zero_timeout(options, opt_str, value, parser):
+ db_opts['pool_timeout'] = 0
+
def _engine_strategy(options, opt_str, value, parser):
if value:
db_opts['strategy'] = value
from test.bootstrap.config import (
_create_testing_engine, _engine_pool, _engine_strategy, _engine_uri, _list_dbs, _log,
_prep_testing_database, _require, _reverse_topological, _server_side_cursors,
- _monkeypatch_cdecimal,
+ _monkeypatch_cdecimal, _zero_timeout,
_set_table_options, base_config, db, db_label, db_url, file_config, post_configure,
pre_configure)
"MS-SQL)")
opt("--mockpool", action="store_true", dest="mockpool",
help="Use mock pool (asserts only one connection used)")
+ opt("--zero-timeout", action="callback", callback=_zero_timeout,
+ help="Set pool_timeout to zero, applies to QueuePool only")
opt("--enginestrategy", action="callback", type="string",
callback=_engine_strategy,
help="Engine strategy (plain or threadlocal, defaults to plain)")