fix undefined variable when raising the 'cannot filter ElasticSearch results on this field' error

This commit is contained in:
Matt Westcott 2014-10-01 16:42:48 +01:00
parent 22fca22b12
commit ba9f580ef0
2 changed files with 8 additions and 1 deletions

View file

@ -140,7 +140,7 @@ class ElasticSearchQuery(object):
# Give error if the field doesn't exist
if field is None:
raise FieldError('Cannot filter ElasticSearch results with field "' + field_name + '". Please add FilterField(\'' + field_name + '\') to ' + self.queryset.model.__name__ + '.search_fields.')
raise FieldError('Cannot filter ElasticSearch results with field "' + field_attname + '". Please add FilterField(\'' + field_attname + '\') to ' + self.queryset.model.__name__ + '.search_fields.')
# Get the name of the field in the index
field_index_name = field.get_index_name(self.queryset.model)

View file

@ -24,6 +24,13 @@ class TestElasticSearchBackend(BackendTests, TestCase):
# Didn't crash, yay!
def test_filter_on_non_filterindex_field(self):
# id is not listed in the search_fields for SearchTest; this should raise a FieldError
from wagtail.wagtailsearch.backends.elasticsearch import FieldError
with self.assertRaises(FieldError):
results = list(self.backend.search("Hello", models.SearchTest, filters=dict(id=42)))
def test_partial_search(self):
# Reset the index
self.backend.reset_index()