Use engine.connect(); don't use private _run_visitor method
SQLAlchemy 1.3 has deprecated engine.contextual_connect() which will be removed in 1.4. Additionally, private methods like Engine._run_visitor will also be removed. Change-Id: I319785d7dd83ffe2c6e651a2494b073becc84684
This commit is contained in:
parent
67d2bb2616
commit
971b9e62df
@ -73,7 +73,7 @@ def run_single_visitor(engine, visitorcallable, element,
|
||||
with support for migrate visitors.
|
||||
"""
|
||||
if connection is None:
|
||||
conn = engine.contextual_connect(close_with_result=False)
|
||||
conn = engine.connect()
|
||||
else:
|
||||
conn = connection
|
||||
visitor = visitorcallable(engine.dialect, conn)
|
||||
|
@ -138,7 +138,7 @@ def alter_column(*p, **k):
|
||||
delta = ColumnDelta(*p, **k)
|
||||
|
||||
visitorcallable = get_engine_visitor(engine, 'schemachanger')
|
||||
engine._run_visitor(visitorcallable, delta)
|
||||
_run_visitor(engine, visitorcallable, delta)
|
||||
|
||||
return delta
|
||||
|
||||
@ -167,6 +167,20 @@ def _to_index(index, table=None, engine=None):
|
||||
return ret
|
||||
|
||||
|
||||
def _run_visitor(
|
||||
connectable, visitorcallable, element, connection=None, **kwargs
|
||||
):
|
||||
if connection is not None:
|
||||
visitorcallable(
|
||||
connection.dialect, connection, **kwargs).traverse_single(element)
|
||||
else:
|
||||
conn = connectable.connect()
|
||||
try:
|
||||
visitorcallable(
|
||||
conn.dialect, conn, **kwargs).traverse_single(element)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
# Python3: if we just use:
|
||||
#
|
||||
@ -574,7 +588,7 @@ populated with defaults
|
||||
self.add_to_table(table)
|
||||
engine = self.table.bind
|
||||
visitorcallable = get_engine_visitor(engine, 'columngenerator')
|
||||
engine._run_visitor(visitorcallable, self, connection, **kwargs)
|
||||
_run_visitor(engine, visitorcallable, self, connection, **kwargs)
|
||||
|
||||
# TODO: reuse existing connection
|
||||
if self.populate_default and self.default is not None:
|
||||
@ -595,7 +609,7 @@ populated with defaults
|
||||
self.table = table
|
||||
engine = self.table.bind
|
||||
visitorcallable = get_engine_visitor(engine, 'columndropper')
|
||||
engine._run_visitor(visitorcallable, self, connection, **kwargs)
|
||||
_run_visitor(engine, visitorcallable, self, connection, **kwargs)
|
||||
self.remove_from_table(self.table, unset_table=False)
|
||||
self.table = None
|
||||
return self
|
||||
@ -689,7 +703,7 @@ class ChangesetIndex(object):
|
||||
engine = self.table.bind
|
||||
self.new_name = name
|
||||
visitorcallable = get_engine_visitor(engine, 'schemachanger')
|
||||
engine._run_visitor(visitorcallable, self, connection, **kwargs)
|
||||
_run_visitor(engine, visitorcallable, self, connection, **kwargs)
|
||||
self.name = name
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user