Allow PYSON Expression as key for PYSON In with dict object

issue10542
This commit is contained in:
Maxime Richez
2021-07-11 11:25:30 +02:00
parent 30ddd9fa54
commit f5f1328c12
3 changed files with 17 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
* Allow PYSON Expression as key for PYSON In with dict object
* Add method to format warning name with records
* Add option to trytond-console to start a readonly transaction
* Add support for werkzeug 2.0
+8 -2
View File
@@ -485,11 +485,17 @@ class In(PYSON):
assert obj.types().issubset({dict, list}), \
'obj must be a dict or a list'
if obj.types() == {dict}:
assert isinstance(key, str), 'key must be a string'
if isinstance(key, PYSON):
assert key.types() == {str}, 'key must be a string'
else:
assert isinstance(key, str), 'key must be a string'
else:
assert isinstance(obj, (dict, list))
if isinstance(obj, dict):
assert isinstance(key, str), 'key must be a string'
if isinstance(key, PYSON):
assert key.types() == {str}, 'key must be a string'
else:
assert isinstance(key, str), 'key must be a string'
self._key = key
self._obj = obj
+8
View File
@@ -461,12 +461,20 @@ class PYSONTestCase(unittest.TestCase):
eval = pyson.PYSONEncoder().encode(pyson.In('foo', {'foo': 'bar'}))
self.assertTrue(pyson.PYSONDecoder().decode(eval))
eval = pyson.PYSONEncoder().encode(pyson.In(
pyson.Eval('test', 'foo'), {'foo': 'bar'}))
self.assertTrue(pyson.PYSONDecoder().decode(eval))
eval = pyson.PYSONEncoder().encode(pyson.In('1', {1: 'bar'}))
self.assertTrue(pyson.PYSONDecoder().decode(eval))
eval = pyson.PYSONEncoder().encode(pyson.In('test', {'foo': 'bar'}))
self.assertFalse(pyson.PYSONDecoder().decode(eval))
eval = pyson.PYSONEncoder().encode(pyson.In(
pyson.Eval('foo', 'test'), {'foo': 'bar'}))
self.assertFalse(pyson.PYSONDecoder().decode(eval))
eval = pyson.PYSONEncoder().encode(pyson.In('1', {2: 'bar'}))
self.assertFalse(pyson.PYSONDecoder().decode(eval))