Don't allow queries with 'IN' predicate with an empty sequence

While SQLAlchemy-based storage tests are run there is invoked an
SAWarning: `The IN-predicate on "image_locations.id" with an empty
sequence`. Fix the issue by making sure that the locations are not
empty.

Co-Authored-By: Alexei Kornienko <akornienko@mirantis.com>
Co-Authored-By: Kamil Rykowski <kamil.rykowski@intel.com>

Change-Id: Iad800a25f0a5ae3538dfc0821977b7086e080097
This commit is contained in:
Alexei Kornienko 2014-08-13 15:02:01 +03:00 committed by Venkatesh Sampath
parent fc44ebb8e9
commit ae97de9674
1 changed files with 6 additions and 5 deletions

View File

@ -876,11 +876,12 @@ def _image_locations_set(context, image_id, locations, session=None):
# NOTE(zhiyan): 1. Remove records from DB for deleted locations
session = session or get_session()
query = session.query(models.ImageLocation).filter_by(
image_id=image_id).filter_by(
deleted=False).filter(~models.ImageLocation.id.in_(
[loc['id']
for loc in locations
if loc.get('id')]))
image_id=image_id).filter_by(deleted=False)
loc_ids = [loc['id'] for loc in locations if loc.get('id')]
if loc_ids:
query = query.filter(~models.ImageLocation.id.in_(loc_ids))
for loc_id in [loc_ref.id for loc_ref in query.all()]:
image_location_delete(context, image_id, loc_id, 'deleted',
session=session)