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:
Cédric Krier
2025-02-26 23:51:39 +01:00
parent 4288e9c6b0
commit cfeb3685f4
2 changed files with 6 additions and 0 deletions
+2
View File
@@ -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(