Skip to content

Commit c72068d

Browse files
committed
db: Replace use of legacy select() calling style
Resolve the following RemovedIn20Warning warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0. Please use the new calling style described at select(). Change-Id: I36e43e30e07f4904c7b49925cefe804af45cff6c Signed-off-by: Stephen Finucane <[email protected]>
1 parent cd9b792 commit c72068d

File tree

4 files changed

+67
-54
lines changed

4 files changed

+67
-54
lines changed

nova/db/main/api.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def _compute_node_select(context, filters=None, limit=None, marker=None):
563563
filters = {}
564564

565565
cn_tbl = sa.alias(models.ComputeNode.__table__, name='cn')
566-
select = sa.select([cn_tbl])
566+
select = sa.select(cn_tbl)
567567

568568
if context.read_deleted == "no":
569569
select = select.where(cn_tbl.c.deleted == 0)
@@ -965,7 +965,7 @@ def compute_node_statistics(context):
965965
inner_sel.c.disk_available_least
966966
).label('disk_available_least'),
967967
]
968-
select = sql.select(agg_cols).select_from(j)
968+
select = sql.select(*agg_cols).select_from(j)
969969
conn = engine.connect()
970970

971971
results = conn.execute(select).fetchone()
@@ -2113,7 +2113,7 @@ def instance_get_all_by_host(context, host, columns_to_join=None):
21132113
def _instance_get_all_uuids_by_hosts(context, hosts):
21142114
itbl = models.Instance.__table__
21152115
default_deleted_value = itbl.c.deleted.default.arg
2116-
sel = sql.select([itbl.c.host, itbl.c.uuid])
2116+
sel = sql.select(itbl.c.host, itbl.c.uuid)
21172117
sel = sel.where(sql.and_(
21182118
itbl.c.deleted == default_deleted_value,
21192119
itbl.c.host.in_(sa.bindparam('hosts', expanding=True))))
@@ -4191,8 +4191,9 @@ def _get_fk_stmts(metadata, conn, table, column, records):
41914191
# AND instance.id IN (<ids>)
41924192
# We need the instance uuids for the <ids> in order to
41934193
# look up the matching instance_extra records.
4194-
select = sql.select([fk.column]).where(
4195-
sql.and_(fk.parent == fk.column, column.in_(records)))
4194+
select = sql.select(fk.column).where(
4195+
sql.and_(fk.parent == fk.column, column.in_(records))
4196+
)
41964197
rows = conn.execute(select).fetchall()
41974198
p_records = [r[0] for r in rows]
41984199
# Then, select rows in the child table that correspond to the
@@ -4205,18 +4206,20 @@ def _get_fk_stmts(metadata, conn, table, column, records):
42054206
# AND instances.uuid IN (<uuids>)
42064207
# We will get the instance_extra ids we need to archive
42074208
# them.
4208-
fk_select = sql.select([fk_column]).where(
4209-
sql.and_(fk.parent == fk.column, fk.column.in_(p_records)))
4209+
fk_select = sql.select(fk_column).where(
4210+
sql.and_(fk.parent == fk.column, fk.column.in_(p_records))
4211+
)
42104212
fk_rows = conn.execute(fk_select).fetchall()
42114213
fk_records = [r[0] for r in fk_rows]
42124214
if fk_records:
42134215
# If we found any records in the child table, create shadow
42144216
# table insert statements for them and prepend them to the
42154217
# deque.
42164218
fk_columns = [c.name for c in fk_table.c]
4217-
fk_insert = fk_shadow_table.insert(inline=True).\
4218-
from_select(fk_columns, sql.select([fk_table],
4219-
fk_column.in_(fk_records)))
4219+
fk_insert = fk_shadow_table.insert(inline=True).from_select(
4220+
fk_columns,
4221+
sql.select(fk_table).where(fk_column.in_(fk_records))
4222+
)
42204223
inserts.appendleft(fk_insert)
42214224
# Create main table delete statements and prepend them to the
42224225
# deque.
@@ -4274,13 +4277,14 @@ def _archive_deleted_rows_for_table(metadata, tablename, max_rows, before,
42744277
deleted_column = table.c.deleted
42754278
columns = [c.name for c in table.c]
42764279

4277-
select = sql.select([column],
4278-
deleted_column != deleted_column.default.arg)
4280+
select = sql.select(column).where(
4281+
deleted_column != deleted_column.default.arg
4282+
)
42794283

42804284
if tablename == "task_log" and task_log:
42814285
# task_log table records are never deleted by anything, so we won't
42824286
# base our select statement on the 'deleted' column status.
4283-
select = sql.select([column])
4287+
select = sql.select(column)
42844288

42854289
if before:
42864290
if tablename != "task_log":
@@ -4307,8 +4311,9 @@ def _archive_deleted_rows_for_table(metadata, tablename, max_rows, before,
43074311
# {tablename: extra_rows_archived}
43084312
extras = collections.defaultdict(int)
43094313
if records:
4310-
insert = shadow_table.insert(inline=True).\
4311-
from_select(columns, sql.select([table], column.in_(records)))
4314+
insert = shadow_table.insert(inline=True).from_select(
4315+
columns, sql.select(table).where(column.in_(records))
4316+
)
43124317
delete = table.delete().where(column.in_(records))
43134318
# Walk FK relationships and add insert/delete statements for rows that
43144319
# refer to this table via FK constraints. fk_inserts and fk_deletes
@@ -4323,7 +4328,9 @@ def _archive_deleted_rows_for_table(metadata, tablename, max_rows, before,
43234328
# table are stored prior to their deletion. Basically the uuids of the
43244329
# archived instances are queried and returned.
43254330
if tablename == "instances":
4326-
query_select = sql.select([table.c.uuid], table.c.id.in_(records))
4331+
query_select = sql.select(table.c.uuid).where(
4332+
table.c.id.in_(records)
4333+
)
43274334
rows = conn.execute(query_select).fetchall()
43284335
deleted_instance_uuids = [r[0] for r in rows]
43294336

nova/tests/fixtures/nova.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,6 @@ def setUp(self):
853853
message=r'The MetaData.bind argument is deprecated .*',
854854
category=sqla_exc.SADeprecationWarning)
855855

856-
warnings.filterwarnings(
857-
'ignore',
858-
module='nova',
859-
message=r'The legacy calling style of select\(\) .*',
860-
category=sqla_exc.SADeprecationWarning)
861-
862856
warnings.filterwarnings(
863857
'ignore',
864858
module='nova',

nova/tests/functional/db/test_archive.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ def _get_table_counts(self):
183183
results = {}
184184
for table in shadow_tables:
185185
r = conn.execute(
186-
sa.select([func.count()]).select_from(table)).fetchone()
186+
sa.select(func.count()).select_from(table)
187+
).fetchone()
187188
results[table.name] = r[0]
188189
return results
189190

nova/tests/unit/db/main/test_api.py

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5751,14 +5751,15 @@ def test_archive_deleted_rows(self):
57515751
where(self.instance_id_mappings.c.uuid.in_(self.uuidstrs[:4]))\
57525752
.values(deleted=1, deleted_at=timeutils.utcnow())
57535753
self.conn.execute(update_statement)
5754-
qiim = sql.select([self.instance_id_mappings]).where(self.
5755-
instance_id_mappings.c.uuid.in_(self.uuidstrs))
5754+
qiim = sql.select(self.instance_id_mappings).where(
5755+
self.instance_id_mappings.c.uuid.in_(self.uuidstrs)
5756+
)
57565757
rows = self.conn.execute(qiim).fetchall()
57575758
# Verify we have 6 in main
57585759
self.assertEqual(len(rows), 6)
5759-
qsiim = sql.select([self.shadow_instance_id_mappings]).\
5760-
where(self.shadow_instance_id_mappings.c.uuid.in_(
5761-
self.uuidstrs))
5760+
qsiim = sql.select(self.shadow_instance_id_mappings).where(
5761+
self.shadow_instance_id_mappings.c.uuid.in_(self.uuidstrs)
5762+
)
57625763
rows = self.conn.execute(qsiim).fetchall()
57635764
# Verify we have 0 in shadow
57645765
self.assertEqual(len(rows), 0)
@@ -5829,10 +5830,12 @@ def test_archive_deleted_rows_before(self):
58295830
where(self.instances.c.uuid.in_(self.uuidstrs[2:4]))\
58305831
.values(deleted=1, deleted_at=timeutils.utcnow())
58315832
self.conn.execute(update_statement)
5832-
qiim = sql.select([self.instances]).where(self.
5833-
instances.c.uuid.in_(self.uuidstrs))
5834-
qsiim = sql.select([self.shadow_instances]).\
5835-
where(self.shadow_instances.c.uuid.in_(self.uuidstrs))
5833+
qiim = sql.select(self.instances).where(
5834+
self. instances.c.uuid.in_(self.uuidstrs)
5835+
)
5836+
qsiim = sql.select(self.shadow_instances).where(
5837+
self.shadow_instances.c.uuid.in_(self.uuidstrs)
5838+
)
58365839

58375840
# Verify we have 6 in main
58385841
rows = self.conn.execute(qiim).fetchall()
@@ -5923,13 +5926,15 @@ def _test_archive_deleted_rows_for_one_uuid_table(self, tablename):
59235926
where(main_table.c.uuid.in_(self.uuidstrs[:4]))\
59245927
.values(deleted=1, deleted_at=timeutils.utcnow())
59255928
self.conn.execute(update_statement)
5926-
qmt = sql.select([main_table]).where(main_table.c.uuid.in_(
5927-
self.uuidstrs))
5929+
qmt = sql.select(main_table).where(
5930+
main_table.c.uuid.in_(self.uuidstrs)
5931+
)
59285932
rows = self.conn.execute(qmt).fetchall()
59295933
# Verify we have 6 in main
59305934
self.assertEqual(len(rows), 6)
5931-
qst = sql.select([shadow_table]).\
5932-
where(shadow_table.c.uuid.in_(self.uuidstrs))
5935+
qst = sql.select(shadow_table).where(
5936+
shadow_table.c.uuid.in_(self.uuidstrs)
5937+
)
59335938
rows = self.conn.execute(qst).fetchall()
59345939
# Verify we have 0 in shadow
59355940
self.assertEqual(len(rows), 0)
@@ -5972,15 +5977,16 @@ def test_archive_deleted_rows_shadow_insertions_equals_deletions(self):
59725977
where(self.instance_id_mappings.c.uuid.in_(self.uuidstrs[:2]))\
59735978
.values(deleted=1)
59745979
self.conn.execute(update_statement)
5975-
qiim = sql.select([self.instance_id_mappings]).where(self.
5976-
instance_id_mappings.c.uuid.in_(self.uuidstrs[:2]))
5980+
qiim = sql.select(self.instance_id_mappings).where(
5981+
self. instance_id_mappings.c.uuid.in_(self.uuidstrs[:2])
5982+
)
59775983
rows = self.conn.execute(qiim).fetchall()
59785984
# Verify we have 2 in main
59795985
self.assertEqual(len(rows), 2)
59805986

5981-
qsiim = sql.select([self.shadow_instance_id_mappings]).\
5982-
where(self.shadow_instance_id_mappings.c.uuid.in_(
5983-
self.uuidstrs[:2]))
5987+
qsiim = sql.select(self.shadow_instance_id_mappings).where(
5988+
self.shadow_instance_id_mappings.c.uuid.in_(self.uuidstrs[:2])
5989+
)
59845990
shadow_rows = self.conn.execute(qsiim).fetchall()
59855991
# Verify we have 0 in shadow
59865992
self.assertEqual(len(shadow_rows), 0)
@@ -6036,22 +6042,25 @@ def test_archive_deleted_rows_2_tables(self):
60366042
.values(deleted=1, deleted_at=timeutils.utcnow())
60376043
self.conn.execute(update_statement2)
60386044
# Verify we have 6 in each main table
6039-
qiim = sql.select([self.instance_id_mappings]).where(
6040-
self.instance_id_mappings.c.uuid.in_(self.uuidstrs))
6045+
qiim = sql.select(self.instance_id_mappings).where(
6046+
self.instance_id_mappings.c.uuid.in_(self.uuidstrs)
6047+
)
60416048
rows = self.conn.execute(qiim).fetchall()
60426049
self.assertEqual(len(rows), 6)
6043-
qi = sql.select([self.instances]).where(self.instances.c.uuid.in_(
6044-
self.uuidstrs))
6050+
qi = sql.select(self.instances).where(
6051+
self.instances.c.uuid.in_(self.uuidstrs)
6052+
)
60456053
rows = self.conn.execute(qi).fetchall()
60466054
self.assertEqual(len(rows), 6)
60476055
# Verify we have 0 in each shadow table
6048-
qsiim = sql.select([self.shadow_instance_id_mappings]).\
6049-
where(self.shadow_instance_id_mappings.c.uuid.in_(
6050-
self.uuidstrs))
6056+
qsiim = sql.select(self.shadow_instance_id_mappings).where(
6057+
self.shadow_instance_id_mappings.c.uuid.in_(self.uuidstrs)
6058+
)
60516059
rows = self.conn.execute(qsiim).fetchall()
60526060
self.assertEqual(len(rows), 0)
6053-
qsi = sql.select([self.shadow_instances]).\
6054-
where(self.shadow_instances.c.uuid.in_(self.uuidstrs))
6061+
qsi = sql.select(self.shadow_instances).where(
6062+
self.shadow_instances.c.uuid.in_(self.uuidstrs)
6063+
)
60556064
rows = self.conn.execute(qsi).fetchall()
60566065
self.assertEqual(len(rows), 0)
60576066
# Archive 7 rows, which should be 4 in one table and 3 in the other.
@@ -6112,13 +6121,15 @@ def test_archive_deleted_rows_task_log(self):
61126121
updated_at=timeutils.utcnow())
61136122
self.conn.execute(update_statement)
61146123
# Verify we have 6 in main
6115-
qtl = sql.select([self.task_log]).where(
6116-
self.task_log.c.id.in_(range(1, 7)))
6124+
qtl = sql.select(self.task_log).where(
6125+
self.task_log.c.id.in_(range(1, 7))
6126+
)
61176127
rows = self.conn.execute(qtl).fetchall()
61186128
self.assertEqual(len(rows), 6)
61196129
# Verify we have 0 in shadow
6120-
qstl = sql.select([self.shadow_task_log]).where(
6121-
self.shadow_task_log.c.id.in_(range(1, 7)))
6130+
qstl = sql.select(self.shadow_task_log).where(
6131+
self.shadow_task_log.c.id.in_(range(1, 7))
6132+
)
61226133
rows = self.conn.execute(qstl).fetchall()
61236134
self.assertEqual(len(rows), 0)
61246135
# Make sure 'before' comparison is for < not <=

0 commit comments

Comments
 (0)