]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix sqlalchemy bug in transfer_get_all_by_project
authorOllie Leahy <oliver.leahy@hp.com>
Thu, 19 Dec 2013 16:11:29 +0000 (16:11 +0000)
committerjohn-griffith <john.griffith@solidfire.com>
Wed, 8 Jan 2014 23:35:14 +0000 (16:35 -0700)
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
cinder/tests/test_volume_transfer.py

index e433dca6bd557f4ed67f499b66ca04a2128706cb..792514dbce95672185a0c24da0b2f3ef54d27ab7 100644 (file)
@@ -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)
 
index 52e47d89c455817c21975c8e621c24b62e3c4824..c794a49eb8d44c43c3327b342b6955bdce7b0111 100644 (file)
@@ -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,