From 1331c650b05e8598aaecd1baba2d4a1df87290ae Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 19 Jun 2023 10:48:33 +0100 Subject: [PATCH] db: Don't rely on autocommit behavior Resolve the following RemovedIn20Warning warning: The current statement is being autocommitted using implicit autocommit, which will be removed in SQLAlchemy 2.0. Use the .begin() method of Engine or Connection in order to use an explicit transaction for DML and DDL statements. Signed-off-by: Stephen Finucane Change-Id: Ibe7503002be9f7cdf13259379ebbf6e9c329a028 --- heat/db/api.py | 23 ++++++++++++++--------- heat/tests/utils.py | 7 ------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/heat/db/api.py b/heat/db/api.py index 68c9e58296..f4484516fa 100644 --- a/heat/db/api.py +++ b/heat/db/api.py @@ -827,7 +827,10 @@ def stack_create(context, values): # some backup stacks may not be found, for reasons that are unclear. earliest = stack_get_by_name(context, stack_name) if earliest is not None and earliest.id != stack_ref.id: - context.session.query(models.Stack).filter_by(id=stack_ref.id).delete() + with context.session.begin(): + context.session.query(models.Stack).filter_by( + id=stack_ref.id, + ).delete() raise exception.StackExists(stack_name=stack_name) return stack_ref @@ -1655,8 +1658,9 @@ def _purge_stacks(stack_infos, engine, meta): def sync_point_delete_all_by_stack_and_traversal(context, stack_id, traversal_id): - rows_deleted = context.session.query(models.SyncPoint).filter_by( - stack_id=stack_id, traversal_id=traversal_id).delete() + with context.session.begin(): + rows_deleted = context.session.query(models.SyncPoint).filter_by( + stack_id=stack_id, traversal_id=traversal_id).delete() return rows_deleted @@ -1681,12 +1685,13 @@ def sync_point_update_input_data(context, entity_id, traversal_id, is_update, atomic_key, input_data): entity_id = str(entity_id) - rows_updated = context.session.query(models.SyncPoint).filter_by( - entity_id=entity_id, - traversal_id=traversal_id, - is_update=is_update, - atomic_key=atomic_key - ).update({"input_data": input_data, "atomic_key": atomic_key + 1}) + with context.session.begin(): + rows_updated = context.session.query(models.SyncPoint).filter_by( + entity_id=entity_id, + traversal_id=traversal_id, + is_update=is_update, + atomic_key=atomic_key + ).update({"input_data": input_data, "atomic_key": atomic_key + 1}) return rows_updated diff --git a/heat/tests/utils.py b/heat/tests/utils.py index 32eee9abcd..b896a32b0b 100644 --- a/heat/tests/utils.py +++ b/heat/tests/utils.py @@ -268,13 +268,6 @@ class WarningsFixture(fixtures.Fixture): # ...but filter everything out until we get around to fixing them # TODO(stephenfin): Fix all of these - warnings.filterwarnings( - 'ignore', - module='heat', - message='The current statement is being autocommitted using ', - category=sqla_exc.SADeprecationWarning, - ) - warnings.filterwarnings( 'ignore', module='heat',