Error while returning result to field.Function(field.Many2many) exist in a one2many relation table

i have a field exist in one2many relation table this field i choose it to be Many2Many field type with coding a function make me display the content of another field exist in another class in line2 on the table one2many : this is how i coded the function inside the class refer to the table one2many relation:
class "work.test" refer to the one2many relation table

class Test(DeactivableMixin, ModelSQL, ModelView, MultiValueMixin):
    __name__ = 'work.test'                                                                                               ```
    field1 = fields.Function(
            fields.Many2Many('', 'test', None, "Status"), 'get_state')
    def get_state(cls,institutions, Name):
        pool = Pool()
        parametr_up = pool.get('process.operation')
        operation1 = Transaction().context.get('operation1')
        institution = 0
        for institution in institutions:
            institutions =[
                    ('institution', '=',,
                    ], limit=1)
            if institutions and parametr_up.operation1 :
              if institution = 2:
                res[] = institutions[0].operation1.convention
                res[] = None
        institution = +1        
        return res 

What does NOT work:
the error :

Traceback (most recent call last):
  File "/trytond/", line 117, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/", line 47, in rpc
    return methods.get(request.rpc_method, _dispatch)(
  File "/trytond/", line 84, in auth_required
    return wrapped(*args, **kwargs)
  File "/trytond/protocols/", line 156, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/trytond/protocols/", line 181, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/trytond/model/", line 872, in read
    row[fname] = getter_result[row['id']]
IndexError: list index out of range

The result of the getter function for a Function field of type Many2Many must be a list of ids.
But also you must ensure to provide a vale for all the records the getter is called for. In your example institutions is replaced in the loop.

Hi , that you for your reply but am sorry i didn’t get you clearly , How i can correct it! or is their any example in one of the standard module can help me to reach my goal !

The problem of your code is that it does not return a value for all of the records that are passed as argument. So this makes tryton crash. You should fix your function to return the proper type for all records.