Issue 10857

Allow Pyson In statement to have str object
Nosy list
ced, mrichez, reviewbot, tbruyere
Assigned to

Created on 2021-10-13.16:16:06 by mrichez, last changed 4 days ago by mrichez.


Author: [hidden] (mrichez)
Date: 2021-10-15.22:13:38

Indeed it's working when adding , []to Eval
Sorry for the noise.

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2021-10-15.19:25:03

For me it is not a bug because the default value which is used to defined the type of an Eval is wrong. It should be ~Eval('data_required', []).contains('toto').

Author: [hidden] (mrichez)
Date: 2021-10-13.16:16:06

pyson.contains is sugar-syntax for pyson.In except we evaluate 'key' instead of object.

data_required = fields.Multiselection([
    ('test', "Test"),
        ('toto', "Toto"),
        ], "Data Required")
test = fields.Char("Test",
            'invisible': ~Eval('data_required').contains('toto')

In case of Eval of a MultiSelection field, object is then a list of string and when doing tests we get this error:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.9/", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/", line 87, in _run_code
exec(code, run_globals)
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/tests/", line 45, in <module>
from trytond.tests.test_tryton import all_suite, modules_suite # noqa: E402
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/tests/", line 41, in <module>
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/", line 105, in start
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/modules/", line 347, in register_classes
the_module = import_module(module)
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/modules/", line 76, in import_module
module = spec.loader.load_module()
File "/home/mrichez/Workspace/tryton/6.0/preciball/", line 7, in <module>
from . import stock
File "/home/mrichez/Workspace/tryton/6.0/preciball/stock/", line 8, in <module>
from . import stock
File "/home/mrichez/Workspace/tryton/6.0/preciball/stock/", line 219, in <module>
class PrintShippingLabelAskDetails(ModelView):
File "/home/mrichez/Workspace/tryton/6.0/preciball/stock/", line 233, in PrintShippingLabelAskDetails
'invisible': ~Eval('fields_required').contains('customer_field')
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/", line 82, in contains
return In(k, self)
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/", line 492, in __init__
assert obj.types().issubset({dict, list}), \
AssertionError: obj must be a dict or a list

Probably this test
should allow also 'str'

Date User Action Args
2021-10-15 22:13:38mrichezsetmessages: + msg71029
2021-10-15 19:25:03cedsetmessages: + msg71027
nosy: + ced
status: testing -> invalid
2021-10-14 10:35:28reviewbotsetmessages: + msg71000
nosy: + reviewbot
2021-10-14 10:35:01mrichezsetkeyword: + review
reviews: 367671002
status: in-progress -> testing
2021-10-13 16:16:06mrichezcreate

Showing 10 items. Show all history (warning: this could be VERY long)