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
(grafted from f7b12ada27377ec42a05b539791855e6f64c497f)

--HG--
branch : 7.0
This commit is contained in:
Cédric Krier committed 2025-02-26 23:51:39 +01:00
1 parent 0cb50865bd
commit 955d9c1e90
2 files changed
+6

No files matched your search

+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]
@@ -36,7 +36,9 @@ class ModelMatchMixinTestCase(unittest.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)
@@ -48,7 +50,9 @@ class ModelMatchMixinTestCase(unittest.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(