Merge "Add NULL check before passing to in_() column operator"

This commit is contained in:
Zuul 2017-10-30 19:44:35 +00:00 committed by Gerrit Code Review
commit 2f9fc5ee5b
2 changed files with 17 additions and 0 deletions

View File

@ -191,6 +191,11 @@ 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(

View File

@ -86,6 +86,18 @@ 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):
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):
obj = api.create_object(self.ctxt, self.model, {'name': 'foo'})
new_objs = api.get_objects(
self.ctxt, self.model, name='foo', status=None)
self.assertEqual(obj, new_objs[0])
def test_get_object_create_update_delete(self):
obj = api.create_object(self.ctxt, self.model, {'name': 'foo'})