django-elasticsearch-dsl
django-elasticsearch-dsl copied to clipboard
fix: TypeError unexpected query set model, compare correct object type, for version 7.4
I am using django-elasticsearch-dsl version 7.4 and I want to contribute with this correction that caused the following problem:
TypeError at /en/search/
Unexpected queryset model (should be: <class 'myshop.models.Product'>, got: <class 'myshop.models.Product'>)
As a consequence and cause of this implementation:
def filter_queryset(self, queryset, keep_search_order=True):
"""
Filter an existing django queryset using the elasticsearch result.
It costs a query to the sql db.
"""
s = self
if s._model is not queryset.model:
raise TypeError( …
'Unexpected queryset model '
'(should be: %s, got: %s)' % (s._model, queryset.model)
)
# Do not query again if the es result is already cached
if not hasattr(self, '_response'):
Verifying and debugging we observe that the variables are different :
We observe that the models are not the same, it is because they are not showing the correct thing.
The solution is to add ._wrapped after ._model