Error unhashable type: 'dict' when using ir.note in a form

To make access to the notes on a record more easily I’ve added a new field to the model like:

messages = fields.One2Many('ir.note', 'resource', 'Notes')

In the view I added:

<page string="Notes" id="notes">
    <field name="messages" colspan="4"/>
</page>

This worked in version 5.4 like you would expect. All the notes linked to that particular record are shown. However after upgrading to 6.0 I got an error from the client:

ERROR:tryton.common.common:  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/view/form_gtk/one2many.py", line 344, in _sig_new
    self._new_single()
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/view/form_gtk/one2many.py", line 361, in _new_single
    WinForm(self.screen, lambda a: update_sequence(), new=True,
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/win_form.py", line 54, in __init__
    self.screen.new(rec_name=rec_name)
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/screen/screen.py", line 627, in new
    group.add(record, self.new_position)
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/model/group.py", line 341, in add
    self.signal('group-changed', record)
  File "/home/tryton/tryton-6.0.4/tryton/signal_event.py", line 15, in signal
    fnct(self, signal_data, *data)
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/model/field.py", line 551, in _group_changed
    parent.signal('record-changed')
  File "/home/tryton/tryton-6.0.4/tryton/signal_event.py", line 15, in signal
    fnct(self, signal_data, *data)
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/model/group.py", line 448, in _record_changed
    self.signal('group-changed', record)
  File "/home/tryton/tryton-6.0.4/tryton/signal_event.py", line 15, in signal
    fnct(self, signal_data, *data)
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/screen/screen.py", line 451, in _group_changed
    self.display()
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/screen/screen.py", line 944, in display
    view.display()
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/view/form.py", line 539, in display
    widget.display()
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/view/form_gtk/one2many.py", line 534, in display
    self.screen.display()
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/screen/screen.py", line 944, in display
    view.display()
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/view/form.py", line 539, in display
    widget.display()
  File "/home/tryton/tryton-6.0.4/tryton/gui/window/view_form/view/form_gtk/multiselection.py", line 79, in display
    self.update_selection(self.record, self.field)
  File "/home/tryton/tryton-6.0.4/tryton/common/selection.py", line 58, in update_selection
    self.init_selection(value)
  File "/home/tryton/tryton-6.0.4/tryton/common/selection.py", line 31, in init_selection
    and key not in self._values2selection):

TypeError: unhashable type: 'dict'

Is this a bug in the client and have I create a bug report or am I doing something wrong?

For me the problem is not directly related to this change but it looks like a MultiSelection field is wrongly defined. I think the selection_change_with contains a dict instead of just field name strings.

I just removed the copy_to_resources field from the note_form.xml because that’s the only MultiSelection I can find in the ir.note. And that was indeed the culprit. I can now add new notes, open the form to see more information.

Now it’s time to dig a bit deeper and see if we can fix it by returning the right data.

Hmm, I think that the problem lies at the client side.

  • adding a new note from my defined view:
    {(('resource', None),): []}

  • adding a new note from the list of notes with the ‘notes’ button
    {(('resource', None),): [], (('resource', 'asset,8'),): []}

Do I need to add some context to my messages field?

It should be fixed by Issue 10603: MultiSelection fails to init with Reference field in selection change set by parent - Tryton issue tracker

Thanks :+1: ! this indeed fixes it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.