]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Eager load snapshot_metadata in *snapshot_get_all
authorMichał Dulko <michal.dulko@intel.com>
Fri, 23 Oct 2015 09:59:48 +0000 (11:59 +0200)
committerMichał Dulko <michal.dulko@intel.com>
Fri, 23 Oct 2015 10:17:36 +0000 (12:17 +0200)
All methods returning snapshot lists in db.sqlalchemy.api are eager
loading snapshot_metadata - besides snapshot_get_all_by_project and
snapshot_get_active_by_window. In case of the latter that fact caused
unit tests to randomly fail because of SQLAlchemy Session sometimes
getting closed before the metadata got lazy loaded. This commit adds
missing options(joinedload('snapshot_metadata')) to these queries.

Change-Id: I72557ebc7af9f3044046965ca79c9fe7c15520fc
Closes-Bug: 1501838

cinder/db/sqlalchemy/api.py

index a7bdceedc45a607544e2b38d19f88a596f021223..5ed047e59fee1add39098cce026ea4924c9d54d4 100644 (file)
@@ -2263,6 +2263,8 @@ def snapshot_get_all_by_project(context, project_id, filters=None, marker=None,
     # No snapshots would match, return empty list
     if not query:
         return []
+
+    query = query.options(joinedload('snapshot_metadata'))
     return query.all()
 
 
@@ -2299,6 +2301,7 @@ def snapshot_get_active_by_window(context, begin, end=None, project_id=None):
     query = query.filter(or_(models.Snapshot.deleted_at == None,  # noqa
                              models.Snapshot.deleted_at > begin))
     query = query.options(joinedload(models.Snapshot.volume))
+    query = query.options(joinedload('snapshot_metadata'))
     if end:
         query = query.filter(models.Snapshot.created_at < end)
     if project_id: