From bff219a04c8b06d95614c544bd831a9e881d973c Mon Sep 17 00:00:00 2001 From: Wolfgang Schnerring Date: Thu, 14 Nov 2024 10:52:55 +0100 Subject: [PATCH] WCM-526: Encapsulate raw sql query in parens, so adding more clauses works if it uses OR That custom query uses parens for OR is already covered in the `joins_different_fields` test. --- core/docs/changelog/WCM-526.change | 1 + core/src/zeit/content/cp/tests/test_automatic.py | 6 +++++- core/src/zeit/contentquery/query.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 core/docs/changelog/WCM-526.change diff --git a/core/docs/changelog/WCM-526.change b/core/docs/changelog/WCM-526.change new file mode 100644 index 0000000000..cd6d16941c --- /dev/null +++ b/core/docs/changelog/WCM-526.change @@ -0,0 +1 @@ +WCM-526: Encapsulate raw sql query in parens, so adding more clauses works if it uses OR diff --git a/core/src/zeit/content/cp/tests/test_automatic.py b/core/src/zeit/content/cp/tests/test_automatic.py index 4b7a5047f6..64f2c3d67a 100644 --- a/core/src/zeit/content/cp/tests/test_automatic.py +++ b/core/src/zeit/content/cp/tests/test_automatic.py @@ -1098,8 +1098,12 @@ def test_cms_content_iter_returns_filled_in_blocks(self): self.assertEqual('International', content[0].ressort) def test_clauses_extend_query(self): + self.area.sql_query = "type='article' OR ressort='International'" + self.area.sql_restrict_time = False IRenderedArea(self.area).values() - query = "...type='article' AND published=true..." + query = """ +...WHERE (type='article' OR ressort='International') AND published=true ORDER... +""" self.assertEllipsis(query, self.connector.search_args[0]) def test_query_order_default(self): diff --git a/core/src/zeit/contentquery/query.py b/core/src/zeit/contentquery/query.py index 5624617e11..493076671a 100644 --- a/core/src/zeit/contentquery/query.py +++ b/core/src/zeit/contentquery/query.py @@ -76,7 +76,7 @@ def total_hits(self): @property def conditions(self): - return select(ConnectorModel).where(sql(self.context.sql_query)) + return select(ConnectorModel).where(sql(f'({self.context.sql_query})')) @property def order(self):