Error when try to create a Dict function field (Ko 4.8. Ok 3.8)


(resteve) #1

Working in 3.8:

esale_slug_langs = fields.Function(fields.Dict(None, 'Slug Langs'), 'get_esale_slug_langs')

def get_esale_slug_langs(self, name):
      return {'ca': 'demo', 'es': demo'}

Same code doesn’t work in 4.8. In GTK client I get message:

sequence item 1: expected string, NoneType found

I try to convert dict to string. I get an error because expect a dict field:

File “/home/resteve/tryton/tryton48/tryton/gui/window/view_form/view/form_gtk/dictionary.py”, line 542, in display
new_key_names = set(value.iterkeys()) - set(self.keys)
AttributeError: ‘unicode’ object has no attribute ‘iterkeys’

What am I doing wrong?


(Sergi Almacellas Abellana) #2

The second traceback is due to the string conversion, the clients expect the value as dict so you should not convert.

From the first traceback it seems that there is some None value that is read. Could you post the full traceback? Maybe it’s because you are using a None as Dictionary Schema, which IIRC is required on the client side to render the dictionary keys/values.


(resteve) #3

GTK:

/home/resteve/tryton/tryton48/tryton/gui/window/view_form/view/form_gtk/char.py:131: Warning: g_value_get_int: assertion ‘G_VALUE_HOLDS_INT (value)’ failed
self.entry.set_text(value)
ERROR:tryton.common.common:None

sequence item 1: expected string, NoneType found

SAO:

Traceback (most recent call last):
File “/trytond/wsgi.py”, line 71, in dispatch_request
return endpoint(request, **request.view_args)
File “/trytond/protocols/dispatcher.py”, line 41, in rpc
request, database_name, *request.rpc_params)
File “/trytond/wsgi.py”, line 42, in auth_required
return wrapped(*args, **kwargs)
File “/trytond/protocols/wrappers.py”, line 122, in wrapper
return func(request, pool, *args, **kwargs)
File “/trytond/protocols/dispatcher.py”, line 151, in _dispatch
obj, method = get_object_method(request, pool)
File “/trytond/protocols/dispatcher.py”, line 126, in get_object_method
obj = pool.get(name, type=type)
File “/trytond/pool.py”, line 180, in get
return self._pool[self.database_name][type][name]
KeyError: u’null’

It’s a dict and same code from v3.8 that is working.


(Cédric Krier) #4

Clearly it can not work. As @pokoli said, it is not allowed to display Dict on a widget without a schema model. Maybe on older version the error was not that visible.