Materialize limit backend queries in read sessions
The limit SQL backend builds a couple of SQLAlchemy queries inside session_for_read contexts but evaluates them after the context has exited. Keep those query executions inside the read session so the database access happens within the intended transaction scope. Use a single-row existence check when looking for referenced limits instead of materializing every matching limit row. Generated-By: pi gpt-5.5 Related-Bug: #2152932 Change-Id: I3808d57ffab52f768420f26c3346a898bf73643a Signed-off-by: Sean Mooney <work@seanmooney.info>
This commit is contained in:
1 file changed
+6
-4
@@ -165,10 +165,12 @@ class UnifiedLimit(base.UnifiedLimitDriverBase):
|
||||
# When updating or deleting a registered limit, we should ensure there
|
||||
# is no reference limit.
|
||||
with sql.session_for_read() as session:
|
||||
limits = session.query(LimitModel).filter_by(
|
||||
registered_limit_id=registered_limit['id']
|
||||
limit = (
|
||||
session.query(LimitModel)
|
||||
.filter_by(registered_limit_id=registered_limit['id'])
|
||||
.first()
|
||||
)
|
||||
if limits.all():
|
||||
if limit:
|
||||
raise exception.RegisteredLimitError(id=registered_limit.id)
|
||||
|
||||
@sql.handle_conflicts(conflict_type='registered_limit')
|
||||
@@ -251,7 +253,7 @@ class UnifiedLimit(base.UnifiedLimitDriverBase):
|
||||
registered_limits = sql.filter_limit_query(
|
||||
RegisteredLimitModel, registered_limits, hints
|
||||
)
|
||||
reg_limits = registered_limits.all()
|
||||
reg_limits = registered_limits.all()
|
||||
if not reg_limits:
|
||||
raise exception.NoLimitReference
|
||||
|
||||
|
||||
Reference in new issue
Block a user