Convert empty string to None for match value
It is not possible from the clients to force to store None value instead of empty string. Closes #13890
This commit is contained in:
@@ -11,6 +11,8 @@ class MatchMixin(object):
|
||||
and matching value as value'''
|
||||
for field_name, pattern_value in pattern.items():
|
||||
value = getattr(self, field_name)
|
||||
if value == '':
|
||||
value = None
|
||||
if not match_none and value is None:
|
||||
continue
|
||||
field = self._fields[field_name]
|
||||
|
||||
@@ -35,7 +35,9 @@ class ModelMatchMixinTestCase(TestCase):
|
||||
(Model(f=(fields.Char("F"), 'foo')), {'f': 'bar'}, False),
|
||||
(Model(f=(fields.Char("F"), 'foo')), {'f': None}, False),
|
||||
(Model(f=(fields.Char("F"), None)), {'f': 'foo'}, True),
|
||||
(Model(f=(fields.Char("F"), '')), {'f': 'foo'}, True),
|
||||
(Model(f=(fields.Char("F"), None)), {'f': None}, True),
|
||||
(Model(f=(fields.Char("F"), '')), {'f': None}, True),
|
||||
]:
|
||||
with self.subTest(record=record, pattern=pattern):
|
||||
self.assertEqual(record.match(pattern), result)
|
||||
@@ -47,7 +49,9 @@ class ModelMatchMixinTestCase(TestCase):
|
||||
(Model(f=(fields.Char("F"), 'foo')), {'f': 'bar'}, False),
|
||||
(Model(f=(fields.Char("F"), 'foo')), {'f': None}, False),
|
||||
(Model(f=(fields.Char("F"), None)), {'f': 'foo'}, False),
|
||||
(Model(f=(fields.Char("F"), '')), {'f': 'foo'}, False),
|
||||
(Model(f=(fields.Char("F"), None)), {'f': None}, True),
|
||||
(Model(f=(fields.Char("F"), '')), {'f': None}, True),
|
||||
]:
|
||||
with self.subTest(record=record, pattern=pattern):
|
||||
self.assertEqual(
|
||||
|
||||
Reference in New Issue
Block a user