Issue 10857

Title
Allow Pyson In statement to have str object
Priority
bug
Status
invalid
Nosy list
ced, mrichez, reviewbot, tbruyere
Assigned to
mrichez
Keywords
review

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

Messages

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",
    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-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