Issue 9997

Title
Searching on reference field with an inverted domain results in a crash
Priority
bug
Status
testing
Nosy list
nicoe, reviewbot
Assigned to
nicoe
Keywords
review

Created on 2021-01-14.11:24:57 by nicoe, last changed 1 week ago by reviewbot.

Messages

Author: [hidden] (nicoe) Tryton committer
Date: 2021-01-14.11:24:57

In case the domain on a reference field has been computed by the domain inversion process a crash will occurs because the search reference a field that might not exist in the model.

Here's the traceback I got when reproducing it on a toy module made on purpose.

68158 140009424287488 [2021-01-13 18:05:52,487] ERROR trytond.protocols.dispatcher <class 'trytond.ir.ui.menu.UIMenu'>.search(*(['AND', ['reference', '=', 'ir.ui.menu,50'], ['reference', '=', 'ir.ui.menu,50']], 0, 1000, None, {'client': 'd5e8f533-1abe-4487-a854-5977db4b94fc', 'language': 'en', 'language_direction': 'ltr', 'groups': [1]}), **{}) from <admin@127.0.0.1>/reference_domain/
Traceback (most recent call last):
  File "/home/nicoe/projets/tryton/tryton-env/RefrenceFieldDomain/trytond/trytond/protocols/dispatcher.py", line 181, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/home/nicoe/projets/tryton/tryton-env/RefrenceFieldDomain/trytond/trytond/ir/ui/menu.py", line 134, in search
    menus = super(UIMenu, cls).search(domain, offset=offset, limit=limit,
  File "/home/nicoe/projets/tryton/tryton-env/RefrenceFieldDomain/trytond/trytond/model/modelsql.py", line 1263, in search
    tables, expression = cls.search_domain(domain)
  File "/home/nicoe/projets/tryton/tryton-env/RefrenceFieldDomain/trytond/trytond/model/modelsql.py", line 1449, in search_domain
    expression = convert(domain)
  File "/home/nicoe/projets/tryton/tryton-env/RefrenceFieldDomain/trytond/trytond/model/modelsql.py", line 1446, in convert
    return And((convert(d) for d in (
  File "/home/nicoe/projets/tryton/tryton-env/RefrenceFieldDomain/trytond/trytond/model/modelsql.py", line 1446, in <genexpr>
    return And((convert(d) for d in (
  File "/home/nicoe/projets/tryton/tryton-env/RefrenceFieldDomain/trytond/trytond/model/modelsql.py", line 1436, in convert
    field = cls._fields[fname]
KeyError: 'reference'

What happens is that the domain sent by the client do not take into account the fact that it will make a search on the model selected in the reference field. Thus the domain should not be ['reference', '=', 'ir.ui.menu,50'] but ['id', '=', 50] (note also that the clause is repeated which I did not investigate yet).

History
Date User Action Args
2021-02-19 22:32:49reviewbotsetmessages: + msg64715
2021-02-14 19:36:56reviewbotsetmessages: + msg64589
2021-02-04 19:47:49reviewbotsetmessages: + msg64312
2021-02-04 18:47:39reviewbotsetmessages: + msg64310
2021-01-29 00:09:49cedsetstatus: chatting -> testing
2021-01-28 13:26:47reviewbotsetmessages: + msg64137
2021-01-25 18:58:26reviewbotsetmessages: + msg64096
2021-01-14 11:47:15reviewbotsetmessages: + msg63879
nosy: + reviewbot
status: unread -> chatting
2021-01-14 11:24:57nicoecreate

Showing 10 items. Show all history (warning: this could be VERY long)