Fix offline network migration for sqlalchemy 1.4+

Sqlalchemy 1.4 dropped support for RowProxy and Row now behaves like a
tuple. This causes row and column iteration to fail using the RowProxy
semantics as the iteration methods are no longer there. Fix this by
checking which method needs to be used. This is necessary for backwards
compatibility with the Xena release for the Yoga branch.

Closes-Bug: #1968647
Change-Id: I6a4adbd87bd59ad3a4b0a8cef187d82f4e128084
This commit is contained in:
Billy Olsen 2022-04-11 19:36:10 -07:00
parent 8109de7d88
commit d20fda9b17
1 changed files with 8 additions and 2 deletions

View File

@ -164,7 +164,10 @@ def allocate_segment(db_session, network_type):
.format(vni_row, alloc_table))
rs = db_session.execute(stmt)
for row in rs:
vni = next(row.itervalues())
if hasattr(row, 'itervalues'):
vni = next(row.itervalues())
else:
vni = next(iter(row))
# A aggregated query will always provide a result, check for NULL
if vni is None:
raise NotFound(
@ -215,7 +218,10 @@ def get_network_segments(db_session, network_type):
' network_type=:network_type')
rs = db_session.execute(stmt, {'network_type': network_type})
for row in rs:
yield row.values()
if hasattr(row, 'values'):
yield row.values()
else:
yield row
def morph_networks(db_session, from_network_type, to_network_type):