Skip to content

Commit

Permalink
Merge pull request #909 from ZeitOnline/WCM-526-parens
Browse files Browse the repository at this point in the history
WCM-526: Encapsulate raw sql query in parens, so adding more clauses works if it uses OR
  • Loading branch information
stollero authored Nov 14, 2024
2 parents aab495c + bff219a commit 0de0d11
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/docs/changelog/WCM-526.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WCM-526: Encapsulate raw sql query in parens, so adding more clauses works if it uses OR
6 changes: 5 additions & 1 deletion core/src/zeit/content/cp/tests/test_automatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion core/src/zeit/contentquery/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0de0d11

Please sign in to comment.