Open roodie opened 4 years ago
Hi @roodie - thanks for the report. Are you able to replicate this issue independently on a fresh Wagtail installation, please? That would assist us enormously in investigating this further.
Sorry, yes, I was able, the sample code is actually from the fresh Wagtail installation and a separate small project.
Hi @roodie.
Does adding page_ptr
to search_fields
as the error says solve the problem for you? There are some limitations to WagtailBackendSearchHandler
, which we tried to highlight in the docs:
This is mostly why we couldn't make it the default option when objects are indexed using the search backend. Whenever a querystring is provided, the search backend needs to know how to parse the full query; including ordering and filters. By default, IndexView orders objects by the primary key (in this case page_ptr
) for consistency, which is why you are getting this specific error message.
You may be able to work around this by specifying an alternative default order via the the ordering
attribute, but you may face similar errors if ordering or filtering by other fields not known to the search backend.
Does adding page_ptr to search_fields as the error says solve the problem for you?
No, I still get the same error message (that was the first thing I tried when I encountered the error).
You may be able to work around this by specifying an alternative default order via the the ordering attribute, but you may face similar errors if ordering or filtering by other fields not known to the search backend.
That would be perfectly okay, but setting the ordering Meta attribute (or the ordering property of the ModelAdmin) does not help. I checked the stacktrace, and it seems that the IndexView adds the '-page_ptr' order field even if I specify another field to be the default:
ordering: ['date', 'date', '-page_ptr']
(The 'date' occurs twice here beause I set it in both the model's Meta and in the ModelAdmin subclass)
Issue Summary
Due to some client requirement, I had to add a ModelAdmin for one of our custom Page types to our Wagtail-based site.
The class itself is very simple:
The date, is_sticky and is_on_index fields are added to she search_fields as filters.
The ModelAdmin page is similarly simple:
The search itself works properly; however, if I click on any of the field headers to sort a queryset, I get the following error:
It doesn't matter if I try to order by a specific NewsPage field, or ny the default Page.title for example.
Full strace:
Technical details
Python version: Python 3.6.8 Django version: 2.2.6 Wagtail version: 2..7 Search backend: Postgres (from contrib)