From d017dbacc89233ec0f786f5af5d760b02b67a7cb Mon Sep 17 00:00:00 2001 From: Ollie Leahy Date: Thu, 19 Dec 2013 16:11:29 +0000 Subject: [PATCH] Fix sqlalchemy bug in transfer_get_all_by_project Because of incorrect use of the sqlalchemy methods joinedload and filter, incorrect lists of volume transfers were being returned by transfer_get_all_by_project(). Change-Id: I378a512611591eec896edd5f217e75f9ff0f8ad3 Closes-Bug: 1262432 --- cinder/db/sqlalchemy/api.py | 9 ++++----- cinder/tests/test_volume_transfer.py | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index e433dca6b..792514dbc 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -2551,8 +2551,8 @@ def _transfer_get(context, transfer_id, session=None): if not is_admin_context(context): volume = models.Volume - query = query.options(joinedload('volume')).\ - filter(volume.project_id == context.project_id) + query = query.filter(models.Transfer.volume_id == volume.id, + volume.project_id == context.project_id) result = query.first() @@ -2590,10 +2590,9 @@ def transfer_get_all(context): def transfer_get_all_by_project(context, project_id): authorize_project_context(context, project_id) - volume = models.Volume query = model_query(context, models.Transfer).\ - options(joinedload('volume')).\ - filter(volume.project_id == project_id) + filter(models.Volume.id == models.Transfer.volume_id, + models.Volume.project_id == project_id) results = query.all() return _translate_transfers(results) diff --git a/cinder/tests/test_volume_transfer.py b/cinder/tests/test_volume_transfer.py index 52e47d89c..c794a49eb 100644 --- a/cinder/tests/test_volume_transfer.py +++ b/cinder/tests/test_volume_transfer.py @@ -110,6 +110,7 @@ class VolumeTransferTestCase(test.TestCase): nctxt = context.RequestContext(user_id='new_user_id', project_id='new_project_id') + utils.create_volume(nctxt, id='2', updated_at=self.updated_at) self.assertRaises(exception.TransferNotFound, tx_api.get, nctxt, -- 2.45.2