From fd98976e7d5febfcb3c999c01161ac34d6b2dcc1 Mon Sep 17 00:00:00 2001 From: Maxime Richez Date: Sun, 11 Jul 2021 11:25:30 +0200 Subject: [PATCH] Allow PYSON Expression as key for PYSON In with dict object issue10542 --- CHANGELOG | 1 + tryton/pyson.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a9f335b0a5..23ee051039 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Allow PYSON Expression as key for PYSON In with dict object * Support Binary field in CSV import/export Version 6.0.0 - 2021-05-03 diff --git a/tryton/pyson.py b/tryton/pyson.py index 0b28b61ddf..e36656aa24 100644 --- a/tryton/pyson.py +++ b/tryton/pyson.py @@ -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