FacetedFilterSearchFilterBackend not working when filtering using "__in" operator
Opened this issue · 1 comments
gmuj commented
Describe the bug
When using filter with in operator and facet param eg:
?facet=state&state__in=published__not_published
I get the following error:
def aggregate(self, request, queryset, view):
> facets = queryset._facets
E AttributeError: 'Search' object has no attribute '_facets'
Environment
Python environment:
pip list
Package Version Editable project location
---------------------------------- -------- ------------------------------------------------------
asgiref 3.4.1
attrs 21.2.0
backports.entry-points-selectable 1.1.0
certifi 2023.5.7
coverage 5.5
distlib 0.3.2
Django 3.2.5
django-cors-headers 3.7.0
django-debug-toolbar 3.2.1
django-debug-toolbar-force 0.1.8
django-elasticsearch-debug-toolbar 2.0.0
django-elasticsearch-dsl 7.3
django-elasticsearch-dsl-drf 0.22.5 /home/gmuj/Playground/django-elasticsearch-dsl-drf/src
django-nine 0.2.4
django-ormex 0.2.1
djangorestframework 3.12.4
elasticsearch 7.17.9
elasticsearch-dsl 7.4.1
factory-boy 2.11.1
Faker 8.1.4
filelock 3.0.12
iniconfig 1.1.1
mock 4.0.3
packaging 21.0
pip 22.3.1
platformdirs 2.0.2
pluggy 0.13.1
py 1.10.0
pyparsing 2.4.7
pytest 6.2.4
pytest-cov 2.12.0
pytest-django 4.3.0
pytest-ordering 0.6
pytest-pythonpath 0.7.3
python-dateutil 2.8.2
pytz 2021.1
selenium 3.141.0
setuptools 58.1.0
six 1.16.0
sqlparse 0.4.1
text-unidecode 1.3
toml 0.10.2
tox 3.23.1
urllib3 1.26.6
virtualenv 20.6.0
python --version
Python 3.9.9
Which version of Elasticsearch are you using?
To Reproduce
Steps to reproduce the behavior:
Add the following test to django_elasticsearch_dsl_drf/tests/test_faceted_filtered_search.py
def test_list_results_facet_and_filter_using_in_operator(self):
self.authenticate()
url = reverse('bookdocument_faceted_filtered-list')
response = self.client.get(url + '?facet=state&state__in={}__{}'.format(
constants.BOOK_PUBLISHING_STATUS_PUBLISHED,
constants.BOOK_PUBLISHING_STATUS_NOT_PUBLISHED
))
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Should contain all published books
self.assertEqual(len(response.data['results']), self.published_count)
# Should contain 1 facet
self.assertEqual(len(response.data['facets']), 1)
self.assertEqual(response.data['facets']['_filter_state']['state']['buckets'], [{
"doc_count": self.published_count,
"key": "published"
}, {
"doc_count": self.not_published_count,
"key": "not_published"
}])
Expected behavior
No error should happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
pixeldot84 commented
@gmuj Hi, did you solve this problem?