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 <stephenfin@redhat.com>
Change-Id: Ibe7503002be9f7cdf13259379ebbf6e9c329a028
This commit is contained in:
Stephen Finucane 2023-06-19 10:48:33 +01:00
parent 591d0ba1be
commit 1331c650b0
2 changed files with 14 additions and 16 deletions

View File

@ -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

View File

@ -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',