Issue 10761

Title
Use UNION for 'Or'-ed domain with subqueries broken domains ['OR', [(), ()]]
Priority
urgent
Status
resolved
Nosy list
ced, nicoe, resteve, reviewbot, roundup-bot
Assigned to
nicoe
Keywords
review

Created on 2021-09-17.11:20:31 by resteve, last changed 2 weeks ago by roundup-bot.

Messages

New changeset 94b1e7e0de18 by Nicolas √Čvrard in branch 'default':
Reconstruct local domain after split_subquery_domain
https://hg.tryton.org/tryton-env/rev/94b1e7e0de18
New changeset 08914e8bb9b1 by Nicolas √Čvrard in branch 'default':
Reconstruct local domain after split_subquery_domain
https://hg.tryton.org/trytond/rev/08914e8bb9b1
Author: [hidden] (nicoe) Tryton committer
Date: 2021-09-17.17:03:28

Here's a patch which should fix the issue

Author: [hidden] (resteve)
Date: 2021-09-17.11:57:39

Other examples when try to search with "OR" and different "clauses", return same results.

>>> Account.search(['OR',('type.expense', '=', True), ('type.revenue', '=', True)])
[Pool().get('account.account')(2), Pool().get('account.account')(3), Pool().get('account.account')(4), Pool().get('account.account')(5), Pool().get('account.account')(6), Pool().get('account.account')(7), Pool().get('account.account')(1)]

>>>  Account.search(['OR',('type.payable', '=', True), ('type.receivable', '=', True)])
[Pool().get('account.account')(2), Pool().get('account.account')(3), Pool().get('account.account')(4), Pool().get('account.account')(5), Pool().get('account.account')(6), Pool().get('account.account')(7), Pool().get('account.account')(1)]

>>> Account.search(['OR',('type.payable', '=', True), ('type.receivable', '=', True)]) ==  Account.search(['OR',('type.expense', '=', True), ('type.revenue', '=', True)])
True

>>> for a in Account.search(['OR',('type.expense', '=', True), ('type.revenue', '=', True)]): a.id, a.type.expense, a.type.revenue, a.type.payable, a.type.receivable
(2, 0, 0, 0, 0)
(3, 1, 0, 0, 0)
(4, 0, 0, 1, 0)
(5, 0, 0, 0, 1)
(6, 0, 1, 0, 0)
(7, 0, 0, 0, 0)
(1, 0, 0, 0, 0)

>>> for a in Account.search(['OR',('type.payable', '=', True), ('type.receivable', '=', True)]): a.id, a.type.expense, a.type.revenue, a.type.payable, a.type.receivable
(2, 0, 0, 0, 0)
(3, 1, 0, 0, 0)
(4, 0, 0, 1, 0)
(5, 0, 0, 0, 1)
(6, 0, 1, 0, 0)
(7, 0, 0, 0, 0)
(1, 0, 0, 0, 0)
Author: [hidden] (resteve)
Date: 2021-09-17.11:20:31

Since issue10658, fail sale_promotion_coupon and web_shop_vue_storefront scenario test in case that domains of the kind ['OR', [(), ()]]

File "/home/raimon/projectes/nandev/nancore/trytond/trytond/modules/sale_promotion_coupon/tests/scenario_sale_promotion_coupon.rst", line 68, in scenario_sale_promotion_coupon.rst
Failed example:
    promotion.save()
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.7/doctest.py", line 1329, in __run
        compileflags, 1), test.globs)
      File "<doctest scenario_sale_promotion_coupon.rst[38]>", line 1, in <module>
        promotion.save()
      File "/home/raimon/projectes/nandev/nancore/proteus/proteus/__init__.py", line 102, in newfunc
        return self.func(owner, [instance], *args, **kwargs)
      File "/home/raimon/projectes/nandev/nancore/proteus/proteus/__init__.py", line 847, in save
        ids = proxy.create(values, context)
      File "/home/raimon/projectes/nandev/nancore/proteus/proteus/config.py", line 188, in __call__
        result = rpc.result(meth(*args, **kwargs))
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/modelsql.py", line 159, in wrapper
        return func(cls, *args, **kwargs)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/modelsql.py", line 670, in create
        field.set(cls, fname, *fargs)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/fields/one2many.py", line 260, in set
        Target.create(to_create)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/modelsql.py", line 159, in wrapper
        return func(cls, *args, **kwargs)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/modelsql.py", line 670, in create
        field.set(cls, fname, *fargs)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/fields/one2many.py", line 260, in set
        Target.create(to_create)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/modelsql.py", line 159, in wrapper
        return func(cls, *args, **kwargs)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/modelsql.py", line 677, in create
        cls._validate(sub_records)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/modelstorage.py", line 85, in wrapper
        return func(*args, **kwargs)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/model/modelstorage.py", line 1429, in _validate
        cls.validate(records)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/modules/sale_promotion_coupon/sale.py", line 150, in validate
        cls.check_unique(numbers)
      File "/home/raimon/projectes/nandev/nancore/trytond/trytond/modules/sale_promotion_coupon/sale.py", line 171, in check_unique
        numbers=numbers))
    trytond.modules.sale_promotion_coupon.exceptions.DuplicateError: The coupons numbered "CODE10" are duplicated. - 

Debug the domain is:

> /home/raimon/projectes/nandev/nancore/trytond/trytond/modules/sale_promotion_coupon/sale.py(166)check_unique()
-> if duplicates:
(Pdb) duplicates
[Pool().get('sale.promotion.coupon.number')(1)]
(Pdb) numbers
[Pool().get('sale.promotion.coupon.number')(1)]
(Pdb) numbers[0].number
'CODE10'
(Pdb) domain
['OR', [('number', '=', 'CODE10'), ('id', '!=', 1), ('coupon.promotion.company', '=', 1)]]
(Pdb) cls.search([])
[Pool().get('sale.promotion.coupon.number')(1)]
History
Date User Action Args
2021-09-28 16:44:24roundup-botsetmessages: + msg70486
2021-09-28 16:44:20roundup-botsetmessages: + msg70485
nosy: + roundup-bot
status: testing -> resolved
2021-09-28 12:02:53reviewbotsetmessages: + msg70479
2021-09-28 03:10:32reviewbotsetmessages: + msg70473
2021-09-28 02:42:15reviewbotsetmessages: + msg70472
2021-09-27 14:43:39cedsetnosy: + ced
2021-09-24 09:29:19cedsetpriority: bug -> urgent
2021-09-17 17:26:02reviewbotsetmessages: + msg70187
nosy: + reviewbot
2021-09-17 17:03:28nicoesetkeyword: + review
messages: + msg70186
nosy: - ced
reviews: 338921002
status: chatting -> testing
2021-09-17 15:26:13cedsetnosy: + ced

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