From 5544f1033fdbbfe7fba170c82407df0dbb78ad10 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 16 Jul 2021 19:25:34 +0100 Subject: Don't use dict-style attribute accesses Resolve the following RemovedIn20Warning warning: Using non-integer/slice indices on Row is deprecated and will be removed in version 2.0; please use row._mapping[], or the mappings() accessor on the Result object. Change-Id: I3a4845216914635e5802a70c2b1be757d82b7a49 Signed-off-by: Stephen Finucane --- oslo_db/sqlalchemy/utils.py | 2 +- oslo_db/tests/fixtures.py | 5 ----- oslo_db/tests/sqlalchemy/test_sqlalchemy.py | 2 +- oslo_db/tests/sqlalchemy/test_utils.py | 12 +++++++----- 4 files changed, 9 insertions(+), 12 deletions(-) (limited to 'oslo_db') diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py index 99da62b..2ab7188 100644 --- a/oslo_db/sqlalchemy/utils.py +++ b/oslo_db/sqlalchemy/utils.py @@ -496,7 +496,7 @@ def drop_old_duplicate_entries_from_table(engine, table_name, is_none = None # workaround for pyflakes delete_condition &= table.c.deleted_at == is_none for name in uc_column_names: - delete_condition &= table.c[name] == row[name] + delete_condition &= table.c[name] == row._mapping[name] rows_to_delete_select = sqlalchemy.sql.select( table.c.id, diff --git a/oslo_db/tests/fixtures.py b/oslo_db/tests/fixtures.py index a1b6929..7db7b78 100644 --- a/oslo_db/tests/fixtures.py +++ b/oslo_db/tests/fixtures.py @@ -47,11 +47,6 @@ class WarningsFixture(fixtures.Fixture): message=r'The Session.begin.subtransactions flag is deprecated .*', category=sqla_exc.SADeprecationWarning) - warnings.filterwarnings( - 'once', - message=r'Using non-integer/slice indices on Row is deprecated .*', - category=sqla_exc.SADeprecationWarning) - warnings.filterwarnings( 'once', message=r'The Engine.execute\(\) method is considered legacy .*', diff --git a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py index 10def6b..ede67c6 100644 --- a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py +++ b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py @@ -327,7 +327,7 @@ class MySQLModeTestCase(db_test_base._MySQLOpportunisticTestCase): self.connection.execute(self.test_table.insert(), bar=value) result = self.connection.execute(self.test_table.select()) - return result.fetchone()['bar'] + return result.fetchone().bar def test_string_too_long(self): value = 'a' * 512 diff --git a/oslo_db/tests/sqlalchemy/test_utils.py b/oslo_db/tests/sqlalchemy/test_utils.py index 7531332..2f61004 100644 --- a/oslo_db/tests/sqlalchemy/test_utils.py +++ b/oslo_db/tests/sqlalchemy/test_utils.py @@ -761,17 +761,19 @@ class TestMigrationUtils(db_test_base._DbTestCase): base_select = table.select() rows_select = base_select.where(table.c.deleted != table.c.id) - row_ids = [row['id'] for row in - self.engine.execute(rows_select).fetchall()] + row_ids = [ + row.id for row in self.engine.execute(rows_select).fetchall() + ] self.assertEqual(len(expected_values), len(row_ids)) for value in expected_values: self.assertIn(value['id'], row_ids) deleted_rows_select = base_select.where( table.c.deleted == table.c.id) - deleted_rows_ids = [row['id'] for row in - self.engine.execute( - deleted_rows_select).fetchall()] + deleted_rows_ids = [ + row.id for row in + self.engine.execute(deleted_rows_select).fetchall() + ] self.assertEqual(len(values) - len(row_ids), len(deleted_rows_ids)) for value in soft_deleted_values: -- cgit v1.2.1