diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-04-23 10:45:11 -0700 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-04-23 10:45:11 -0700 |
commit | d216298073ac6657728bdeb56598f3e5124e2d67 (patch) | |
tree | a7b735d0187fcbb6691c69480b84122f2f9da57c /lib/sqlalchemy/schema.py | |
parent | 3452a2ba03bcf75eeec60141f040d661e15eaa2f (diff) | |
download | sqlalchemy-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/schema.py')
-rw-r--r-- | lib/sqlalchemy/schema.py | 48 |
1 files changed, 26 insertions, 22 deletions
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``. |