changeset 08914e8bb9b1 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=08914e8bb9b1
description:
        Reconstruct local domain after split_subquery_domain

        issue10761
        review338921002
diffstat:

 trytond/model/modelsql.py      |  12 ++++++++----
 trytond/tests/test_modelsql.py |  31 +++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)

diffs (70 lines):

diff -r 100cdd3d479a -r 08914e8bb9b1 trytond/model/modelsql.py
--- a/trytond/model/modelsql.py Tue Sep 28 10:59:56 2021 +0200
+++ b/trytond/model/modelsql.py Tue Sep 28 16:44:12 2021 +0200
@@ -1264,17 +1264,21 @@
         Rule = pool.get('ir.rule')
 
         rule_domain = Rule.domain_get(cls.__name__, mode='read')
+        joined_domains = None
         if domain and domain[0] == 'OR':
             local_domains, subquery_domains = split_subquery_domain(domain)
-        else:
-            local_domains, subquery_domains = None, None
+            if subquery_domains:
+                joined_domains = subquery_domains
+                if local_domains:
+                    local_domains.insert(0, 'OR')
+                    joined_domains.append(local_domains)
 
         # In case the search uses subqueries it's more efficient to use a UNION
         # of queries than using clauses with some JOIN because databases can
         # used indexes
-        if subquery_domains:
+        if joined_domains is not None:
             union_tables = []
-            for sub_domain in [['OR'] + local_domains] + subquery_domains:
+            for sub_domain in joined_domains:
                 tables, expression = cls.search_domain(sub_domain)
                 if rule_domain:
                     tables, domain_exp = cls.search_domain(
diff -r 100cdd3d479a -r 08914e8bb9b1 trytond/tests/test_modelsql.py
--- a/trytond/tests/test_modelsql.py    Tue Sep 28 10:59:56 2021 +0200
+++ b/trytond/tests/test_modelsql.py    Tue Sep 28 16:44:12 2021 +0200
@@ -573,6 +573,37 @@
             Model.search(domain),
             result_without_split)
 
+    @with_transaction()
+    def test_search_or_to_union_no_local_clauses(self):
+        """
+        Test searching for 'OR'-ed domain without local clauses
+        """
+        pool = Pool()
+        Model = pool.get('test.modelsql.read')
+
+        Model.create([{
+                    'name': 'A',
+                    }, {
+                    'name': 'B',
+                    }, {
+                    'name': 'C',
+                    'targets': [('create', [{
+                                    'name': 'C.A',
+                                    }]),
+                        ],
+                    }])
+
+        domain = ['OR',
+            ('targets.name', 'ilike', '%A'),
+            ]
+        with patch('trytond.model.modelsql.split_subquery_domain') as no_split:
+            # Mocking in order not to trigger the split
+            no_split.side_effect = lambda d: (d, [])
+            result_without_split = Model.search(domain)
+        self.assertEqual(
+            Model.search(domain),
+            result_without_split)
+
     def test_split_subquery_domain_empty(self):
         """
         Test the split of domains in local and relation parts (empty domain)

Reply via email to