You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a query set has certain order_by conditions added to it, such as Lower('some_field'), the Elasticsearch backend produces a stack trace when order_by_relevance=False is used to search the set.
Steps to Reproduce
$ date -u
Fri Jul 15 13:58:47 UTC 2022
$ sw_vers
ProductName: macOS
ProductVersion: 12.4
BuildVersion: 21F79
$ python3 --version
Python 3.10.5
$ python3 -m venv venv
$ . venv/bin/activate
(venv) $ pip install --quiet --upgrade wagtail==3.0.1 pip setuptools
(venv) $ wagtail start issue
Creating a Wagtail project called issue
Success! issue has been created
(venv) $ cd issue
(venv) $ echo 'elasticsearch~=7.17' >> requirements.txt
(venv) $ pip install --quiet --requirement requirements.txt
(venv) $ cat >>issue/settings/base.py <<EOF
WAGTAILSEARCH_BACKENDS = {
'default': {
'ATOMIC_REBUILD': True,
'AUTO_UPDATE': True,
'BACKEND': 'wagtail.search.backends.elasticsearch7',
'INDEX': 'wagtail',
'INDEX_SETTINGS': {},
'OPTIONS': {},
'TIMEOUT': 5,
'URLS': ['http://localhost:9200'],
}
}
EOF
(venv) $ ./manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, home, sessions, taggit, wagtailadmin, wagtailcore, wagtaildocs, wagtailembeds, wagtailforms, wagtailimages, wagtailredirects, wagtailsearch, wagtailusers
…
Applying wagtailusers.0009_userprofile_verbose_name_plural... OK
Applying wagtailusers.0010_userprofile_updated_comments_notifications... OK
(venv) $ ./manage.py createsuperuser --no-input --username admin --email admin@admin.com
Superuser created successfully.
(venv) $ ./manage.py shell <<EOF
from wagtail.core.models import Page, Site
from django.db.models.functions import Lower
root = Site.objects.filter(is_default_site=True).first().root_page
p1 = Page(title='hello world')
root.add_child(instance=p1)
p1.save()
p2 = Page(title='Hello World')
root.add_child(instance=p2)
p2.save()
Page.objects.all().order_by(Lower('title')).search('world', order_by_relevance=False)
EOF
Traceback (most recent call last):
File "issue/./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
…
File "venv/lib/python3.10/site-packages/wagtail/search/backends/base.py", line 174, in _get_order_by
if field_name.startswith("-"):
AttributeError: 'Lower' object has no attribute 'startswith'
Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?
It feels like a bug because the documentation at this page states that order_by_relevance=False preserves the QuerySet's ordering:
I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes
Technical details
Python version: 3.10.5
Django version: 4.0.6
Wagtail version: 3.0.1
Browser version: N/A
The text was updated successfully, but these errors were encountered:
Issue Summary
When a query set has certain
order_by
conditions added to it, such asLower('some_field')
, the Elasticsearch backend produces a stack trace whenorder_by_relevance=False
is used to search the set.Steps to Reproduce
It feels like a bug because the documentation at this page states that
order_by_relevance=False
preserves theQuerySet
's ordering:Technical details
The text was updated successfully, but these errors were encountered: