Issue 9997

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

Created on 2021-01-14.11:24:57 by nicoe, last changed 4 weeks ago by roundup-bot.

Messages

New changeset 95a67741ae49 by Nicolas Évrard in branch '5.8':
Use specific search domain for reference field searches
https://hg.tryton.org/trytond/rev/95a67741ae49

New changeset 801d153ef88d by Nicolas Évrard in branch '5.6':
Use specific search domain for reference field searches
https://hg.tryton.org/trytond/rev/801d153ef88d
New changeset d8984ce5a8e6 by Nicolas Évrard in branch '5.8':
Use specific search domain for reference field searches
https://hg.tryton.org/tryton/rev/d8984ce5a8e6

New changeset 72ccc8121d55 by Nicolas Évrard in branch '5.6':
Use specific search domain for reference field searches
https://hg.tryton.org/tryton/rev/72ccc8121d55

New changeset af77eea40b5b by Nicolas Évrard in branch '5.0':
Use specific search domain for reference field searches
https://hg.tryton.org/tryton/rev/af77eea40b5b
New changeset edfe33c6a4f2 by Nicolas Évrard in branch '5.8':
Use specific search domain for reference field searches
https://hg.tryton.org/sao/rev/edfe33c6a4f2

New changeset 31c8626e1723 by Nicolas Évrard in branch '5.6':
Use specific search domain for reference field searches
https://hg.tryton.org/sao/rev/31c8626e1723

New changeset 96c7d07a3eed by Nicolas Évrard in branch '5.0':
Use specific search domain for reference field searches
https://hg.tryton.org/sao/rev/96c7d07a3eed
New changeset a901f8ed66d8 by Nicolas Évrard in branch 'default':
Use specific search domain for reference field searches
https://hg.tryton.org/tryton-env/rev/a901f8ed66d8
New changeset ee23aca64b26 by Nicolas Évrard in branch 'default':
Use specific search domain for reference field searches
https://hg.tryton.org/trytond/rev/ee23aca64b26
New changeset 558aeef898cd by Nicolas Évrard in branch 'default':
Use specific search domain for reference field searches
https://hg.tryton.org/tryton/rev/558aeef898cd
New changeset eab088332684 by Nicolas Évrard in branch 'default':
Use specific search domain for reference field searches
https://hg.tryton.org/sao/rev/eab088332684
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-04-20 00:00:31roundup-botsetmessages: + msg66741
2021-04-19 23:59:55roundup-botsetmessages: + msg66738
2021-04-19 23:59:47roundup-botsetkeyword: - backport
messages: + msg66736
2021-04-12 20:54:20roundup-botsetmessages: + msg66517
2021-04-12 20:54:15roundup-botsetmessages: + msg66516
2021-04-12 20:54:13roundup-botsetmessages: + msg66515
2021-04-12 20:54:11roundup-botsetmessages: + msg66514
nosy: + roundup-bot
status: testing -> resolved
2021-04-11 21:07:51cedsetkeyword: + backport
2021-04-11 19:19:59reviewbotsetmessages: + msg66431
2021-04-09 13:57:05reviewbotsetmessages: + msg66218

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