From 00aadf570b5468b62ad1d843dd5b88d7cf11baf1 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 7 Sep 2022 23:39:40 +0100 Subject: db: Resolve SAWarning warnings Resolve the following SAWarning warning: SELECT statement has a cartesian product between FROM element(s) "foo" and FROM element "bar". Apply join condition(s) between each element to resolve. This was happening because we were filtering instances of ConductorHardwareInterfaces by the state of the Conductor referenced by the 'conductor_id' field *without* joining the Conductor table. By adding the join, we can avoid this cartesian product. Change-Id: I2c20d7a7c1de41d4d0057fabc1d953b5bfb5b216 Signed-off-by: Stephen Finucane --- ironic/db/sqlalchemy/api.py | 6 ++++-- ironic/tests/base.py | 10 ---------- 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'ironic') diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py index 93a211fc3..31ec9647e 100644 --- a/ironic/db/sqlalchemy/api.py +++ b/ironic/db/sqlalchemy/api.py @@ -1379,12 +1379,14 @@ class Connection(api.Connection): def list_hardware_type_interfaces(self, hardware_types): with _session_for_read() as session: - query = (session.query(models.ConductorHardwareInterfaces) + query = (session.query(models.ConductorHardwareInterfaces, + models.Conductor) + .join(models.Conductor) .filter(models.ConductorHardwareInterfaces.hardware_type .in_(hardware_types))) query = _filter_active_conductors(query) - return query.all() + return [row[0] for row in query] @oslo_db_api.retry_on_deadlock def register_conductor_hardware_interfaces(self, conductor_id, interfaces): diff --git a/ironic/tests/base.py b/ironic/tests/base.py index 348f15c20..1ed6cab70 100644 --- a/ironic/tests/base.py +++ b/ironic/tests/base.py @@ -125,16 +125,6 @@ class WarningsFixture(fixtures.Fixture): category=sqla_exc.SAWarning, ) - # ...but filter everything out until we get around to fixing them - # TODO(stephenfin): Fix all of these - - warnings.filterwarnings( - 'ignore', - module='ironic', - message='SELECT statement has a cartesian product ', - category=sqla_exc.SAWarning, - ) - # FIXME(stephenfin): We can remove this once oslo.db is fixed # https://review.opendev.org/c/openstack/oslo.db/+/856453 warnings.filterwarnings( -- cgit v1.2.1