Add support for JSON/JSONB on postgresql for dict fields
Currently the Dict field is created as a Text field on postgresql backend. If you manually change the schema into json with:
alter table t alter column j type jsonb using j::text::jsonb;
And you try to read some table data the following exception is raised:
Traceback (most recent call last):
File "/trytond/wsgi.py", line 47, 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 39, in auth_required
return wrapped(*args, **kwargs)
File "/trytond/protocols/wrappers.py", line 105, in wrapper
return func(request, pool, *args, **kwargs)
File "/trytond/protocols/dispatcher.py", line 162, in _dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File "/trytond/model/modelsql.py", line 797, in read
getter_results = field.get(ids, cls, field_list, values=result)
File "/trytond/model/fields/function.py", line 98, in get
return dict((name, call(name)) for name in names)
File "/trytond/model/fields/function.py", line 98, in <genexpr>
return dict((name, call(name)) for name in names)
File "/trytond/model/fields/function.py", line 92, in call
return dict((r.id, method(r, name)) for r in records)
File "/trytond/model/fields/function.py", line 92, in <genexpr>
return dict((r.id, method(r, name)) for r in records)
File "/trytond/modules/aritmos_sii/sii.py", line 111, in get_invoice_number
if not self.json:
File "/trytond/model/fields/field.py", line 267, in __get__
return inst.__getattr__(self.name)
File "/trytond/model/modelstorage.py", line 1369, in __getattr__
read_data = self.read(list(ids), ffields.keys())
File "/trytond/model/modelsql.py", line 778, in read
getter_result = field.get(ids, cls, fname, values=result)
File "/trytond/model/fields/dict.py", line 31, in get
data = json.loads(data, object_hook=JSONDecoder())
File "/json/__init__.py", line 352, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
That's because the code loads a field which is already a dict field, so we must not convert it.
Everything else work as expected.