summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-07-16 12:08:44 +0100
committerStephen Finucane <stephenfin@redhat.com>2021-07-29 16:37:44 +0100
commit8d7607266c51d91b289526cd571d70993c278c8f (patch)
treeef5d3212c4ec418f10d81774d661182a2b38afdc
parent4c1eb966c08d29214c1905e74965f4109f41b013 (diff)
downloadoslo-db-8d7607266c51d91b289526cd571d70993c278c8f.tar.gz
Remove legacy calling style of select()
Resolve the following SADeprecationWarning 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: Ic5f7240e790425d2689c6870483748650a49bc3d Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
-rw-r--r--doc/source/user/usage.rst2
-rw-r--r--oslo_db/sqlalchemy/engines.py6
-rw-r--r--oslo_db/sqlalchemy/utils.py11
-rw-r--r--oslo_db/tests/fixtures.py5
-rw-r--r--oslo_db/tests/sqlalchemy/test_enginefacade.py2
-rw-r--r--oslo_db/tests/sqlalchemy/test_exc_filters.py10
-rw-r--r--oslo_db/tests/sqlalchemy/test_sqlalchemy.py2
-rw-r--r--oslo_db/tests/sqlalchemy/test_update_match.py2
-rw-r--r--oslo_db/tests/sqlalchemy/test_utils.py10
9 files changed, 26 insertions, 24 deletions
diff --git a/doc/source/user/usage.rst b/doc/source/user/usage.rst
index 2fe883c..8037e0c 100644
--- a/doc/source/user/usage.rst
+++ b/doc/source/user/usage.rst
@@ -84,7 +84,7 @@ is preferred:
@enginefacade.reader.connection
def _refresh_from_db(context, cache):
- sel = sa.select([table.c.id, table.c.name])
+ sel = sa.select(table.c.id, table.c.name)
res = context.connection.execute(sel).fetchall()
cache.id_cache = {r[1]: r[0] for r in res}
cache.str_cache = {r[0]: r[1] for r in res}
diff --git a/oslo_db/sqlalchemy/engines.py b/oslo_db/sqlalchemy/engines.py
index de3719a..32c4def 100644
--- a/oslo_db/sqlalchemy/engines.py
+++ b/oslo_db/sqlalchemy/engines.py
@@ -70,7 +70,7 @@ def _connect_ping_listener(connection, branch):
try:
# run a SELECT 1. use a core select() so that
# any details like that needed by the backend are handled.
- connection.scalar(select([1]))
+ connection.scalar(select(1))
except exception.DBConnectionError:
# catch DBConnectionError, which is raised by the filter
# system.
@@ -80,7 +80,7 @@ def _connect_ping_listener(connection, branch):
# run the select again to re-validate the Connection.
LOG.exception(
'Database connection was found disconnected; reconnecting')
- connection.scalar(select([1]))
+ connection.scalar(select(1))
finally:
connection.should_close_with_result = save_should_close_with_result
@@ -362,7 +362,7 @@ def _init_events(engine, sqlite_synchronous=True, sqlite_fk=False, **kw):
# emit our own BEGIN, checking for existing
# transactional state
if 'in_transaction' not in conn.info:
- conn.execute("BEGIN")
+ conn.execute(sqlalchemy.text("BEGIN"))
conn.info['in_transaction'] = True
@sqlalchemy.event.listens_for(engine, "rollback")
diff --git a/oslo_db/sqlalchemy/utils.py b/oslo_db/sqlalchemy/utils.py
index 2329b4b..70db00b 100644
--- a/oslo_db/sqlalchemy/utils.py
+++ b/oslo_db/sqlalchemy/utils.py
@@ -485,8 +485,12 @@ def drop_old_duplicate_entries_from_table(engine, table_name,
columns_for_select.extend(columns_for_group_by)
duplicated_rows_select = sqlalchemy.sql.select(
- columns_for_select, group_by=columns_for_group_by,
- having=func.count(table.c.id) > 1)
+ *columns_for_select,
+ ).group_by(
+ *columns_for_group_by
+ ).having(
+ func.count(table.c.id) > 1
+ )
for row in engine.execute(duplicated_rows_select).fetchall():
# NOTE(boris-42): Do not remove row that has the biggest ID.
@@ -497,7 +501,8 @@ def drop_old_duplicate_entries_from_table(engine, table_name,
delete_condition &= table.c[name] == row[name]
rows_to_delete_select = sqlalchemy.sql.select(
- [table.c.id]).where(delete_condition)
+ table.c.id,
+ ).where(delete_condition)
for row in engine.execute(rows_to_delete_select).fetchall():
LOG.info("Deleting duplicated row with id: %(id)s from table: "
"%(table)s", dict(id=row[0], table=table_name))
diff --git a/oslo_db/tests/fixtures.py b/oslo_db/tests/fixtures.py
index dbdffba..e5da906 100644
--- a/oslo_db/tests/fixtures.py
+++ b/oslo_db/tests/fixtures.py
@@ -39,11 +39,6 @@ class WarningsFixture(fixtures.Fixture):
warnings.filterwarnings(
'once',
- message=r'The legacy calling style of select\(\) is deprecated .*',
- category=sqla_exc.SADeprecationWarning)
-
- warnings.filterwarnings(
- 'once',
message=r'The MetaData.bind argument is deprecated .*',
category=sqla_exc.SADeprecationWarning)
diff --git a/oslo_db/tests/sqlalchemy/test_enginefacade.py b/oslo_db/tests/sqlalchemy/test_enginefacade.py
index a1dd446..b24892b 100644
--- a/oslo_db/tests/sqlalchemy/test_enginefacade.py
+++ b/oslo_db/tests/sqlalchemy/test_enginefacade.py
@@ -2004,7 +2004,7 @@ class LiveFacadeTest(db_test_base._DbTestCase):
def test_external_writer_in_reader(self):
context = oslo_context.RequestContext()
with enginefacade.reader.using(context) as session:
- ping = session.scalar(select([1]))
+ ping = session.scalar(select(1))
self.assertEqual(1, ping)
# we're definitely a reader
diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py
index 95b8f0d..8d7e5ba 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -1165,7 +1165,7 @@ class TestDBDisconnected(TestsExceptionFilter):
with self._fixture(dialect_name, exc_obj, 1, is_disconnect):
conn = self.engine.connect()
with conn.begin():
- self.assertEqual(1, conn.scalar(sqla.select([1])))
+ self.assertEqual(1, conn.scalar(sqla.select(1)))
self.assertFalse(conn.closed)
self.assertFalse(conn.invalidated)
self.assertTrue(conn.in_transaction())
@@ -1178,7 +1178,7 @@ class TestDBDisconnected(TestsExceptionFilter):
# test implicit execution
with self._fixture(dialect_name, exc_obj, 1):
- self.assertEqual(1, self.engine.scalar(sqla.select([1])))
+ self.assertEqual(1, self.engine.scalar(sqla.select(1)))
def test_mariadb_error_1927(self):
for code in [1927]:
@@ -1286,7 +1286,7 @@ class TestDBConnectRetry(TestsExceptionFilter):
2, -1
)
# conn is good
- self.assertEqual(1, conn.scalar(sqla.select([1])))
+ self.assertEqual(1, conn.scalar(sqla.select(1)))
def test_connect_retry_past_failure(self):
conn = self._run_test(
@@ -1295,7 +1295,7 @@ class TestDBConnectRetry(TestsExceptionFilter):
2, 3
)
# conn is good
- self.assertEqual(1, conn.scalar(sqla.select([1])))
+ self.assertEqual(1, conn.scalar(sqla.select(1)))
def test_connect_retry_not_candidate_exception(self):
self.assertRaises(
@@ -1362,7 +1362,7 @@ class TestDBConnectPingWrapping(TestsExceptionFilter):
self, dialect_name, exc_obj, is_disconnect=True):
with self._fixture(dialect_name, exc_obj, 3, is_disconnect):
conn = self.engine.connect()
- self.assertEqual(1, conn.scalar(sqla.select([1])))
+ self.assertEqual(1, conn.scalar(sqla.select(1)))
conn.close()
with self._fixture(dialect_name, exc_obj, 1, is_disconnect):
diff --git a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
index 43ab145..b400249 100644
--- a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
+++ b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
@@ -121,7 +121,7 @@ class SQLiteSavepointTest(db_test_base._DbTestCase):
0,
conn.scalar(
sqlalchemy.select(
- [sqlalchemy.func.count(self.test_table.c.id)],
+ sqlalchemy.func.count(self.test_table.c.id),
).select_from(self.test_table)
)
)
diff --git a/oslo_db/tests/sqlalchemy/test_update_match.py b/oslo_db/tests/sqlalchemy/test_update_match.py
index 9ee61c5..b313862 100644
--- a/oslo_db/tests/sqlalchemy/test_update_match.py
+++ b/oslo_db/tests/sqlalchemy/test_update_match.py
@@ -120,7 +120,7 @@ class UpdateMatchTest(db_test_base._DbTestCase):
def _assert_row(self, pk, values):
row = self.session.execute(
- sql.select([MyModel.__table__]).where(MyModel.__table__.c.id == pk)
+ sql.select(MyModel.__table__).where(MyModel.__table__.c.id == pk)
).first()
values['id'] = pk
self.assertEqual(values, dict(row))
diff --git a/oslo_db/tests/sqlalchemy/test_utils.py b/oslo_db/tests/sqlalchemy/test_utils.py
index 47d587d..de757d0 100644
--- a/oslo_db/tests/sqlalchemy/test_utils.py
+++ b/oslo_db/tests/sqlalchemy/test_utils.py
@@ -629,7 +629,7 @@ class TestPaginateQueryActualSQL(test_base.BaseTestCase):
marker=FakeTable(user_id='hello',
enabled=False))
expected_core_sql = (
- select([FakeTable]).
+ select(FakeTable).
order_by(sqlalchemy.asc(FakeTable.enabled)).
where(cast(FakeTable.enabled, Integer) > 0).
limit(5)
@@ -648,7 +648,7 @@ class TestPaginateQueryActualSQL(test_base.BaseTestCase):
['user_id', 'some_hybrid'],
sort_dirs=['asc', 'desc'])
expected_core_sql = (
- select([FakeTable]).
+ select(FakeTable).
order_by(sqlalchemy.asc(FakeTable.user_id)).
order_by(sqlalchemy.desc(FakeTable.some_hybrid)).
limit(5)
@@ -716,8 +716,10 @@ class TestMigrationUtils(db_test_base._DbTestCase):
uniq_values.add(uniq_value)
expected_ids.append(value['id'])
- real_ids = [row[0] for row in
- self.engine.execute(select([test_table.c.id])).fetchall()]
+ real_ids = [
+ row[0] for row in
+ self.engine.execute(select(test_table.c.id)).fetchall()
+ ]
self.assertEqual(len(expected_ids), len(real_ids))
for id_ in expected_ids: