From e4da60740bb6ff3daad619d71c5771001e782094 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 22 Mar 2023 14:33:04 +0100 Subject: [PATCH] [sqlalchemy-20] Do not use strings for aatribute names in loader options The method ``get_l3_agents_by_router_ids`` is retrieving the ``RouterL3AgentBinding`` registers along with the ``Agent`` information. This left outer join should be explictly defined using the database model. Expected query: SELECT routerl3agentbindings.router_id AS ... FROM routerl3agentbindings LEFT OUTER JOIN agents ON agents.id = routerl3agentbindings.l3_agent_id WHERE routerl3agentbindings.router_id IN (XXX) Closes-Bug: #2012662 Change-Id: Ife9ba5d774934d2cd1a86b3281b78e854d88de3c --- neutron/objects/l3agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neutron/objects/l3agent.py b/neutron/objects/l3agent.py index b339a368e63..51cc70a318e 100644 --- a/neutron/objects/l3agent.py +++ b/neutron/objects/l3agent.py @@ -13,7 +13,6 @@ from neutron_lib.db import api as db_api from neutron_lib.objects import common_types from oslo_versionedobjects import fields as obj_fields -from sqlalchemy.orm import joinedload from sqlalchemy import sql @@ -46,7 +45,8 @@ class RouterL3AgentBinding(base.NeutronDbObject): @db_api.CONTEXT_READER def get_l3_agents_by_router_ids(cls, context, router_ids): query = context.session.query(l3agent.RouterL3AgentBinding) - query = query.options(joinedload('l3_agent')).filter( + query = query.outerjoin(agent_model.Agent) + query = query.filter( l3agent.RouterL3AgentBinding.router_id.in_(router_ids)) return [db_obj.l3_agent for db_obj in query.all()]