Replace deprecated SQLAlchemy "with_lockmode"

This method was deprecated in sqlalchemy 0.9 [1][2]
and finally removed in version 1.4, which we'll
be adopting very soon [3]. No end-user impact is
expected, we're using a rudimentary form of the
new "with_for_update" method.

[1] https://docs.sqlalchemy.org/en/13/changelog/migration_09.html?highlight=with_lockmode#new-for-update-support-on-select-query
[2] https://docs.sqlalchemy.org/en/13/orm/query.html#sqlalchemy.orm.query.Query.with_lockmode
[3] http://lists.openstack.org/pipermail/openstack-discuss/2021-April/022094.html

Change-Id: I0a3a89bd0741f6f91c39baaa68149551d8f4ce54
Partial-Bug: #1926399
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
(cherry picked from commit cadfe04b1f)
This commit is contained in:
Goutham Pacha Ravi 2021-05-18 18:58:16 -07:00
parent 1f402ba588
commit 3532f5d654
1 changed files with 4 additions and 4 deletions

View File

@ -943,7 +943,7 @@ def _get_share_type_quota_usages(context, session, project_id, share_type_id):
).filter( ).filter(
models.QuotaUsage.project_id == project_id, models.QuotaUsage.project_id == project_id,
models.QuotaUsage.share_type_id == share_type_id, models.QuotaUsage.share_type_id == share_type_id,
).with_lockmode('update').all() ).with_for_update().all()
return {row.resource: row for row in rows} return {row.resource: row for row in rows}
@ -955,7 +955,7 @@ def _get_user_quota_usages(context, session, project_id, user_id):
filter_by(project_id=project_id). filter_by(project_id=project_id).
filter(or_(models.QuotaUsage.user_id == user_id, filter(or_(models.QuotaUsage.user_id == user_id,
models.QuotaUsage.user_id is None)). models.QuotaUsage.user_id is None)).
with_lockmode('update'). with_for_update().
all()) all())
return {row.resource: row for row in rows} return {row.resource: row for row in rows}
@ -966,7 +966,7 @@ def _get_project_quota_usages(context, session, project_id):
session=session). session=session).
filter_by(project_id=project_id). filter_by(project_id=project_id).
filter(models.QuotaUsage.share_type_id is None). filter(models.QuotaUsage.share_type_id is None).
with_lockmode('update'). with_for_update().
all()) all())
result = dict() result = dict()
# Get the total count of in_use,reserved # Get the total count of in_use,reserved
@ -1239,7 +1239,7 @@ def _quota_reservations_query(session, context, reservations):
read_deleted="no", read_deleted="no",
session=session). session=session).
filter(models.Reservation.uuid.in_(reservations)). filter(models.Reservation.uuid.in_(reservations)).
with_lockmode('update')) with_for_update())
@require_context @require_context