Fixed :meth:`.MetaData.reflect` to correctly use
the given :class:`.Connection`, if given, without opening a second connection from that connection's :class:`.Engine`. [ticket:2604]
This commit is contained in:
parent
7a03aded91
commit
bef89a2440
|
@ -8,6 +8,15 @@
|
||||||
:version: 0.7.10
|
:version: 0.7.10
|
||||||
:released:
|
:released:
|
||||||
|
|
||||||
|
.. change::
|
||||||
|
:tags: engine, bug
|
||||||
|
:tickets: 2604
|
||||||
|
|
||||||
|
Fixed :meth:`.MetaData.reflect` to correctly use
|
||||||
|
the given :class:`.Connection`, if given, without
|
||||||
|
opening a second connection from that connection's
|
||||||
|
:class:`.Engine`.
|
||||||
|
|
||||||
.. change::
|
.. change::
|
||||||
:tags: mssql, bug
|
:tags: mssql, bug
|
||||||
:tickets:2607
|
:tickets:2607
|
||||||
|
|
|
@ -2485,13 +2485,20 @@ class MetaData(SchemaItem):
|
||||||
arguments and should return a true value for any table to reflect.
|
arguments and should return a true value for any table to reflect.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
reflect_opts = {'autoload': True}
|
|
||||||
if bind is None:
|
if bind is None:
|
||||||
bind = _bind_or_error(self)
|
bind = _bind_or_error(self)
|
||||||
conn = None
|
|
||||||
|
if bind.engine is not bind:
|
||||||
|
conn = bind
|
||||||
|
close = False
|
||||||
else:
|
else:
|
||||||
reflect_opts['autoload_with'] = bind
|
|
||||||
conn = bind.contextual_connect()
|
conn = bind.contextual_connect()
|
||||||
|
close = True
|
||||||
|
|
||||||
|
reflect_opts = {
|
||||||
|
'autoload': True,
|
||||||
|
'autoload_with': bind
|
||||||
|
}
|
||||||
|
|
||||||
if schema is None:
|
if schema is None:
|
||||||
schema = self.schema
|
schema = self.schema
|
||||||
|
@ -2504,7 +2511,7 @@ class MetaData(SchemaItem):
|
||||||
connection=conn))
|
connection=conn))
|
||||||
if views:
|
if views:
|
||||||
available.update(
|
available.update(
|
||||||
bind.dialect.get_view_names(conn or bind, schema)
|
bind.dialect.get_view_names(conn, schema)
|
||||||
)
|
)
|
||||||
|
|
||||||
current = set(self.tables.iterkeys())
|
current = set(self.tables.iterkeys())
|
||||||
|
@ -2527,8 +2534,7 @@ class MetaData(SchemaItem):
|
||||||
for name in load:
|
for name in load:
|
||||||
Table(name, self, **reflect_opts)
|
Table(name, self, **reflect_opts)
|
||||||
finally:
|
finally:
|
||||||
if conn is not None and \
|
if close:
|
||||||
conn is not bind:
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def append_ddl_listener(self, event_name, listener):
|
def append_ddl_listener(self, event_name, listener):
|
||||||
|
|
|
@ -700,6 +700,31 @@ class ReflectionTest(fixtures.TestBase, ComparesTables):
|
||||||
table_b2 = Table('false', meta2, autoload=True)
|
table_b2 = Table('false', meta2, autoload=True)
|
||||||
table_c2 = Table('is', meta2, autoload=True)
|
table_c2 = Table('is', meta2, autoload=True)
|
||||||
|
|
||||||
|
@testing.provide_metadata
|
||||||
|
def _test_reflect_uses_bind(self, fn):
|
||||||
|
from sqlalchemy.pool import AssertionPool
|
||||||
|
e = engines.testing_engine(options={"poolclass": AssertionPool})
|
||||||
|
fn(e)
|
||||||
|
|
||||||
|
def test_reflect_uses_bind_constructor_conn(self):
|
||||||
|
self._test_reflect_uses_bind(lambda e: MetaData(e.connect(),
|
||||||
|
reflect=True))
|
||||||
|
|
||||||
|
def test_reflect_uses_bind_constructor_engine(self):
|
||||||
|
self._test_reflect_uses_bind(lambda e: MetaData(e, reflect=True))
|
||||||
|
|
||||||
|
def test_reflect_uses_bind_constructor_conn_reflect(self):
|
||||||
|
self._test_reflect_uses_bind(lambda e: MetaData(e.connect()).reflect())
|
||||||
|
|
||||||
|
def test_reflect_uses_bind_constructor_engine_reflect(self):
|
||||||
|
self._test_reflect_uses_bind(lambda e: MetaData(e).reflect())
|
||||||
|
|
||||||
|
def test_reflect_uses_bind_conn_reflect(self):
|
||||||
|
self._test_reflect_uses_bind(lambda e: MetaData().reflect(e.connect()))
|
||||||
|
|
||||||
|
def test_reflect_uses_bind_engine_reflect(self):
|
||||||
|
self._test_reflect_uses_bind(lambda e: MetaData().reflect(e))
|
||||||
|
|
||||||
@testing.provide_metadata
|
@testing.provide_metadata
|
||||||
def test_reflect_all(self):
|
def test_reflect_all(self):
|
||||||
existing = testing.db.table_names()
|
existing = testing.db.table_names()
|
||||||
|
|
Loading…
Reference in New Issue