Skip to content

Commit 64a5187

Browse files
kajinamitrichardcruise87
authored andcommitted
Replace deprecated SQLAlchemy noload and return get_all_orm for L7 policies
noload was deprecated in SQLAlchemy 2.1 due to confusing behavior caused by this option[1]. Replace it by raiseload so that we ensure that these non-loaded attributes are not read. The model.to_date_model() call within the API attempts to load all relationships. However this prevents us from replacing noload, which is deprecated in SQLAlchemy 2.1, due to lack of explicit join calls. Return the full ORM directly instead, to leave loading to the later logics. Now matches all the other get_all_API methods. [1] sqlalchemy/sqlalchemy#11045 Assisted-by: Opencode with GPT 5.5 Co-authored-by: Takashi Kajinami <[email protected]> Change-Id: Id1a93ed67f3c12168b33e3bdbfc6e8e1bd209bca Signed-off-by: Richard Cruise <[email protected]>
1 parent 0aa3556 commit 64a5187

2 files changed

Lines changed: 22 additions & 28 deletions

File tree

‎octavia/db/repositories.py‎

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from oslo_serialization import jsonutils
2929
from oslo_utils import timeutils
3030
from oslo_utils import uuidutils
31-
from sqlalchemy.orm import noload
31+
from sqlalchemy.orm import raiseload
3232
from sqlalchemy.orm import Session
3333
from sqlalchemy.orm import subqueryload
3434
from sqlalchemy import select
@@ -262,7 +262,7 @@ def get_all_deleted_expiring(self, session, exp_age):
262262
else:
263263
query = query.filter_by(provisioning_status=consts.DELETED)
264264
# Do not load any relationship
265-
query = query.options(noload('*'))
265+
query = query.options(raiseload('*'))
266266
model_list = query.all()
267267

268268
id_list = [model.id for model in model_list]
@@ -785,7 +785,7 @@ def get_all_API_list(self, session, pagination_helper=None, **filters):
785785
subqueryload(models.LoadBalancer.pools),
786786
subqueryload(models.LoadBalancer.listeners),
787787
subqueryload(models.LoadBalancer._tags),
788-
noload('*'))
788+
raiseload('*'))
789789

790790
return super().get_all_orm(
791791
session, pagination_helper=pagination_helper,
@@ -911,7 +911,7 @@ def get_all_API_list(self, session, pagination_helper=None, **filters):
911911
query_options = (
912912
subqueryload(models.HealthMonitor.pool),
913913
subqueryload(models.HealthMonitor._tags),
914-
noload('*'))
914+
raiseload('*'))
915915

916916
return super().get_all_orm(
917917
session, pagination_helper=pagination_helper,
@@ -977,7 +977,7 @@ def get_all_API_list(self, session, pagination_helper=None, **filters):
977977
subqueryload(models.Pool.members),
978978
subqueryload(models.Pool.session_persistence),
979979
subqueryload(models.Pool._tags),
980-
noload('*'))
980+
raiseload('*'))
981981

982982
return super().get_all_orm(
983983
session, pagination_helper=pagination_helper,
@@ -1013,7 +1013,7 @@ def get_all_API_list(self, session, pagination_helper=None, **filters):
10131013
query_options = (
10141014
subqueryload(models.Member.pool),
10151015
subqueryload(models.Member._tags),
1016-
noload('*'))
1016+
raiseload('*'))
10171017

10181018
return super().get_all_orm(
10191019
session, pagination_helper=pagination_helper,
@@ -1057,7 +1057,7 @@ def get_all_API_list(self, session, pagination_helper=None, **filters):
10571057
subqueryload(models.Listener.sni_containers),
10581058
subqueryload(models.Listener._tags),
10591059
subqueryload(models.Listener.allowed_cidrs),
1060-
noload('*'))
1060+
raiseload('*'))
10611061

10621062
return super().get_all_orm(
10631063
session, pagination_helper=pagination_helper,
@@ -1268,7 +1268,7 @@ def get_all_API_list(self, session, pagination_helper=None, **filters):
12681268
# no-load (blank) the tables we don't need
12691269
query_options = (
12701270
subqueryload(models.Amphora.load_balancer),
1271-
noload('*'))
1271+
raiseload('*'))
12721272

12731273
return super().get_all_orm(
12741274
session, pagination_helper=pagination_helper,
@@ -1747,7 +1747,7 @@ def get_all_API_list(self, session, pagination_helper=None, **filters):
17471747
query_options = (
17481748
subqueryload(models.L7Rule.l7policy),
17491749
subqueryload(models.L7Rule._tags),
1750-
noload('*'))
1750+
raiseload('*'))
17511751

17521752
return super().get_all_orm(
17531753
session, pagination_helper=pagination_helper,
@@ -1836,30 +1836,16 @@ def get_all(self, session, pagination_helper=None, **filters):
18361836
return data_model_list, links
18371837

18381838
def get_all_API_list(self, session, pagination_helper=None, **filters):
1839-
deleted = filters.pop('show_deleted', True)
1840-
query = session.query(self.model_class).filter_by(
1841-
**filters)
1842-
1843-
query = query.options(
1839+
query_options = (
18441840
subqueryload(models.L7Policy.l7rules),
18451841
subqueryload(models.L7Policy.listener),
18461842
subqueryload(models.L7Policy.redirect_pool),
18471843
subqueryload(models.L7Policy._tags),
1848-
noload('*'))
1844+
raiseload('*'))
18491845

1850-
if not deleted:
1851-
query = query.filter(
1852-
self.model_class.provisioning_status != consts.DELETED)
1853-
1854-
if pagination_helper:
1855-
model_list, links = pagination_helper.apply(
1856-
query, self.model_class)
1857-
else:
1858-
links = None
1859-
model_list = query.order_by(self.model_class.position).all()
1860-
1861-
data_model_list = [model.to_data_model() for model in model_list]
1862-
return data_model_list, links
1846+
return super().get_all_orm(
1847+
session, pagination_helper=pagination_helper,
1848+
query_options=query_options, **filters)
18631849

18641850
def update(self, session, id, **model_kwargs):
18651851
l7policy_db = session.query(self.model_class).filter_by(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed an issue where some of the get_all_API_list calls were using inconsistent
5+
DB queries. This was likely due to ordering requirements in the response
6+
which are no longer relevant since pagination works. Updated to use the get_all_orm
7+
call to be consistent with other endpoints
8+

0 commit comments

Comments
 (0)