Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WCM-526: Encapsulate raw sql query in parens, so adding more clauses works if it uses OR #909

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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