changeset 4f3207199ad9 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=4f3207199ad9
description:
        Use first the dotted name variable in the PYSON context

        issue11109
        review383991002
diffstat:

 trytond/pyson.py            |   2 +-
 trytond/tests/test_pyson.py |  13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)

diffs (35 lines):

diff -r 0e2aa531af42 -r 4f3207199ad9 trytond/pyson.py
--- a/trytond/pyson.py  Tue Jan 04 22:30:41 2022 +0100
+++ b/trytond/pyson.py  Tue Jan 11 23:03:06 2022 +0100
@@ -154,7 +154,7 @@
 
     @staticmethod
     def eval(dct, context):
-        if '.' in dct['v']:
+        if '.' in dct['v'] and dct['v'] not in context:
             base, name = dct['v'].split('.', 1)
             return Eval.eval({
                     'v': name,
diff -r 0e2aa531af42 -r 4f3207199ad9 trytond/tests/test_pyson.py
--- a/trytond/tests/test_pyson.py       Tue Jan 04 22:30:41 2022 +0100
+++ b/trytond/tests/test_pyson.py       Tue Jan 11 23:03:06 2022 +0100
@@ -846,6 +846,19 @@
                 ]:
             self.assertEqual(pyson.PYSONDecoder(ctx).decode(eval), result)
 
+    def test_Eval_dot_notation_in_context(self):
+        "Test pyson.Eval with dot notation in context"
+
+        eval = pyson.PYSONEncoder().encode(pyson.Eval('foo.bar', 0))
+        ctx = {
+            'foo.bar': 1,
+            'foo': {
+                'bar': 0,
+                },
+            }
+
+        self.assertEqual(pyson.PYSONDecoder(ctx).decode(eval), 1)
+
     def test_eval_true(self):
         "Test PYSON.eval JS true"
         self.assertEqual(eval('true', pyson.CONTEXT), True)

Reply via email to