diff --git a/cinder/backup/api.py b/cinder/backup/api.py index 748b608f67e..68f2132788e 100644 --- a/cinder/backup/api.py +++ b/cinder/backup/api.py @@ -490,16 +490,18 @@ class API(base.Base): 'project_id': context.project_id, 'volume_id': IMPORT_VOLUME_ID, 'status': fields.BackupStatus.CREATING, + 'deleted_at': None, + 'deleted': False, 'metadata': {} } try: # Try to get the backup with that ID in all projects even among # deleted entries. - backup = objects.BackupImport.get_by_id(context, - backup_record['id'], - read_deleted='yes', - project_only=False) + backup = objects.BackupImport.get_by_id( + context.elevated(read_deleted='yes'), + backup_record['id'], + project_only=False) # If record exists and it's not deleted we cannot proceed with the # import diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 7eda162160f..4c35cfb569f 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -6784,8 +6784,10 @@ def worker_destroy(context, **filters): @require_context def resource_exists(context, model, resource_id, session=None): + conditions = [model.id == resource_id] # Match non deleted resources by the id - conditions = [model.id == resource_id, ~model.deleted] + if 'no' == context.read_deleted: + conditions.append(~model.deleted) # If the context is not admin we limit it to the context's project if is_user_context(context) and hasattr(model, 'project_id'): conditions.append(model.project_id == context.project_id)