Message 70996

Author
mrichez
Date
2021-10-13.16:16:06
Message id
70996

Content

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",
    states={
            'invisible': ~Eval('data_required').contains('toto')
                },
                depends=['data_required'])
...

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/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/tests/run-tests.py", 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/test_tryton.py", line 41, in <module>
Pool.start()
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/pool.py", line 105, in start
register_classes()
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/modules/__init__.py", line 347, in register_classes
the_module = import_module(module)
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/modules/__init__.py", line 76, in import_module
module = spec.loader.load_module()
File "/home/mrichez/Workspace/tryton/6.0/preciball/__init__.py", line 7, in <module>
from . import stock
File "/home/mrichez/Workspace/tryton/6.0/preciball/stock/__init__.py", line 8, in <module>
from . import stock
File "/home/mrichez/Workspace/tryton/6.0/preciball/stock/stock.py", line 219, in <module>
class PrintShippingLabelAskDetails(ModelView):
File "/home/mrichez/Workspace/tryton/6.0/preciball/stock/stock.py", line 233, in PrintShippingLabelAskDetails
'invisible': ~Eval('fields_required').contains('customer_field')
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/pyson.py", line 82, in contains
return In(k, self)
File "/home/mrichez/Workspace/tryton/6.0/trytond/trytond/pyson.py", line 492, in __init__
assert obj.types().issubset({dict, list}), \
AssertionError: obj must be a dict or a list

Probably this test https://hg.tryton.org/trytond/file/default/trytond/pyson.py#l485
should allow also 'str'

History
Date User Action Args
2021-10-13 16:16:06mrichezsetrecipients: + tbruyere
2021-10-13 16:16:06mrichezsetmessageid: <1634134566.6702304.UGU2TP66FDOEQ4JZ.issue10857@tryton.org>
2021-10-13 16:16:06mrichezlinkissue10857 messages
2021-10-13 16:16:06mrichezcreate

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