summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-04-23 10:45:11 -0700
committerMike Bayer <mike_mp@zzzcomputing.com>2011-04-23 10:45:11 -0700
commitd216298073ac6657728bdeb56598f3e5124e2d67 (patch)
treea7b735d0187fcbb6691c69480b84122f2f9da57c /lib/sqlalchemy
parent3452a2ba03bcf75eeec60141f040d661e15eaa2f (diff)
downloadsqlalchemy-d216298073ac6657728bdeb56598f3e5124e2d67.tar.gz
- metadata.reflect() and reflection.Inspector()
had some reliance on GC to close connections which were internally procured, fixed this. - added --zero-timeout option to nose fixture, sets pool_timeout to zero
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/engine/reflection.py9
-rw-r--r--lib/sqlalchemy/schema.py48
2 files changed, 31 insertions, 26 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index 72eb27c4e..ca4360325 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -80,10 +80,6 @@ class Inspector(object):
:meth:`Inspector.from_engine`
"""
-
- # ensure initialized
- bind.connect()
-
# this might not be a connection, it could be an engine.
self.bind = bind
@@ -92,6 +88,11 @@ class Inspector(object):
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 = {}
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index 72516acd6..47fc7b08c 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -2308,32 +2308,36 @@ class MetaData(SchemaItem):
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``.