Reorder checks in apply_filters in db/_model_query
Function _kwargs_to_filters() in objects/db/api.py creates a filter dictionary where all the values are made iterables except in the case of StringMatchingFilterObj objects. As a consequence, when processing such a filter, function apply_filters() in db/_model_query.py must check if a value is a StringMatchingFilterObj before assuming it is an iterable. Change-Id: I1b43a06f6e35eaa61c6e6770076a167e6ee83987 Closes-Bug: #1724177
This commit is contained in:
parent
76ec5ca105
commit
0bbfad2de7
|
@ -191,11 +191,6 @@ def apply_filters(query, model, filters, context=None):
|
|||
# do multiple equals matches
|
||||
query = query.filter(
|
||||
or_(*[column == v for v in value]))
|
||||
elif None in value:
|
||||
# in_() operator does not support NULL element so we have
|
||||
# to do multiple equals matches
|
||||
query = query.filter(
|
||||
or_(*[column == v for v in value]))
|
||||
elif isinstance(value, obj_utils.StringMatchingFilterObj):
|
||||
if value.is_contains:
|
||||
query = query.filter(
|
||||
|
@ -206,6 +201,11 @@ def apply_filters(query, model, filters, context=None):
|
|||
elif value.is_ends:
|
||||
query = query.filter(
|
||||
column.endswith(value.ends))
|
||||
elif None in value:
|
||||
# in_() operator does not support NULL element so we have
|
||||
# to do multiple equals matches
|
||||
query = query.filter(
|
||||
or_(*[column == v for v in value]))
|
||||
else:
|
||||
query = query.filter(column.in_(value))
|
||||
elif key == 'shared' and hasattr(model, 'rbac_entries'):
|
||||
|
|
|
@ -86,13 +86,13 @@ class CRUDScenarioTestCase(testlib_api.SqlTestCase):
|
|||
self.model = models_v2.Network
|
||||
self.ctxt = context.get_admin_context()
|
||||
|
||||
def test_get_object_with_none_value_in_filters(self):
|
||||
def test_get_object_with_None_value_in_filters(self):
|
||||
obj = api.create_object(self.ctxt, self.model, {'name': 'foo'})
|
||||
new_obj = api.get_object(
|
||||
self.ctxt, self.model, name='foo', status=None)
|
||||
self.assertEqual(obj, new_obj)
|
||||
|
||||
def test_get_objects_with_none_value_in_filters(self):
|
||||
def test_get_objects_with_None_value_in_filters(self):
|
||||
obj = api.create_object(self.ctxt, self.model, {'name': 'foo'})
|
||||
new_objs = api.get_objects(
|
||||
self.ctxt, self.model, name='foo', status=None)
|
||||
|
|
Loading…
Reference in New Issue