Merge "fix to get soft-deleted objects on db model query"

This commit is contained in:
Zuul 2023-07-17 21:33:47 +00:00 committed by Gerrit Code Review
commit e31be16130
3 changed files with 32 additions and 1 deletions

View File

@ -289,8 +289,10 @@ def model_query(context, model, *args, **kwargs):
kwargs['project_id'] = context.project_id
if read_deleted in ('no', 'n', False):
kwargs['deleted'] = False
elif read_deleted in ('yes', 'y', True):
elif read_deleted == 'only':
kwargs['deleted'] = True
elif read_deleted in ('yes', 'y', True):
pass
return db_utils.model_query(
model=model,

View File

@ -339,6 +339,29 @@ class ShareDatabaseAPITestCase(test.TestCase):
super(ShareDatabaseAPITestCase, self).setUp()
self.ctxt = context.get_admin_context()
@ddt.data('yes', 'no', 'only')
def test_share_read_deleted(self, read_deleted):
share = db_utils.create_share()
test_ctxt = context.get_admin_context(read_deleted=read_deleted)
admin_ctxt = context.get_admin_context(read_deleted='yes')
if read_deleted in ('yes', 'no'):
self.assertIsNotNone(db_api.share_get(test_ctxt, share['id']))
elif read_deleted == 'only':
self.assertRaises(exception.NotFound, db_api.share_get,
test_ctxt, share['id'])
# we don't use the to be tested context here and
# we need to delete the share instance before we can delete the share
db_api.share_instance_delete(admin_ctxt, share['instance']['id'])
db_api.share_delete(admin_ctxt, share['id'])
if read_deleted in ('yes', 'only'):
self.assertIsNotNone(db_api.share_get(test_ctxt, share['id']))
elif read_deleted == 'no':
self.assertRaises(exception.NotFound, db_api.share_get,
test_ctxt, share['id'])
def test_share_filter_by_host_with_pools(self):
share_instances = [[
db_api.share_create(self.ctxt, {'host': value}).instance

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Internal sqlalchemy model_query has been fixed to honor the options of the
`read_deleted` parameter. For more details, please refer to
`launchpad bug #2015094 <https://bugs.launchpad.net/manila/+bug/2015094>`_