Skip to content

Commit 2b7d147

Browse files
authored
Fix bug caused by child having multiple terms set under the index order by classifier (#617)
Currently, if a page has `index_order_by_classifier` set, and one or more of its live children have more than one `ClassifierTerm` under that classifier set, Django will return a programming error `more than one row returned by a subquery used as an expression`. This makes sense, as it is trying to sort on an order that is non deterministic. To fix, we slice the queryset to only ever contain a single term, which should also always be the highest order term due to the default ordering for the classifier terms.
1 parent 9591169 commit 2b7d147

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ stages:
153153
- task: UsePythonVersion@0
154154
displayName: 'Use Python version'
155155
inputs:
156-
versionSpec: '3.12'
156+
versionSpec: '3.11'
157157
architecture: 'x64'
158158

159159
- script: python -m pip install -r requirements-ci.txt

coderedcms/models/page_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def get_index_children(self):
489489
classifier=self.index_order_by_classifier,
490490
# Reverse ManyToMany of `coderedpage.classifier_terms`.
491491
coderedpage=models.OuterRef("pk"),
492-
)
492+
)[:1]
493493
query = query.annotate(
494494
term_sort_order=models.Subquery(terms.values("sort_order"))
495495
)

docs/releases/v3.0.2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ v3.0.2 release notes
55
Bug fixes
66
---------
77

8-
* Fix site search: when searching by specific page models (``search_filterable=True``) on MySQL databases, no search results would be returned. We have applied a workaround to this bug in Wagtail, with one small caveat: for example when filtering by a model ``WebPage``, the search results on SQLite and Postgres will return results for ``WebPage`` and anything inherting from ``WebPage``. On MySQL, it will ONLY return ``WebPage`` results. *However, the bug still persists in the Wagtail Admin search and will need to be fixed in a future version of Wagtail.*
8+
* Fix site search: when searching by specific page models (``search_filterable=True``) on MySQL databases, no search results would be returned. We have applied a workaround to this bug in Wagtail, with one small caveat: for example when filtering by a model ``WebPage``, the search results on SQLite and Postgres will return results for ``WebPage`` and anything inheriting from ``WebPage``. On MySQL, it will ONLY return ``WebPage`` results. *However, the bug still persists in the Wagtail Admin search and will need to be fixed in a future version of Wagtail.*
99

1010

1111
Thank you!

0 commit comments

Comments
 (0)