diff options
author | Stephen Finucane <sfinucan@redhat.com> | 2022-09-07 23:39:40 +0100 |
---|---|---|
committer | Stephen Finucane <sfinucan@redhat.com> | 2023-04-19 10:44:19 +0100 |
commit | 00aadf570b5468b62ad1d843dd5b88d7cf11baf1 (patch) | |
tree | 04c2569d98185001467f55a69c7d06f7dc4d34b2 /ironic | |
parent | 8ef9db15704c0c2cb1342c7c1554bfa8d8a7a2e3 (diff) | |
download | ironic-00aadf570b5468b62ad1d843dd5b88d7cf11baf1.tar.gz |
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 <sfinucan@redhat.com>
Diffstat (limited to 'ironic')
-rw-r--r-- | ironic/db/sqlalchemy/api.py | 6 | ||||
-rw-r--r-- | ironic/tests/base.py | 10 |
2 files changed, 4 insertions, 12 deletions
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( |