Skip to content

Commit c9a53ea

Browse files
committed
Fixed a bug so that ValuesListQuerySet now works with the __in filter. Thanks to jcdyer for the report!
1 parent 187c4a6 commit c9a53ea

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

haystack/backends/solr_backend.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ def matching_all_fragment(self):
380380
def build_query_fragment(self, field, filter_type, value):
381381
result = ''
382382

383+
# Handle when we've got a ``ValuesListQuerySet``...
384+
if hasattr(value, 'values_list'):
385+
value = list(value)
386+
383387
if not isinstance(value, (list, tuple)):
384388
# Convert whatever we find to what pysolr wants.
385389
value = self.backend.conn._from_python(value)

haystack/backends/whoosh_backend.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ def build_query_fragment(self, field, filter_type, value):
605605
result = ''
606606
is_datetime = False
607607

608+
# Handle when we've got a ``ValuesListQuerySet``...
609+
if hasattr(value, 'values_list'):
610+
value = list(value)
611+
608612
if hasattr(value, 'strftime'):
609613
is_datetime = True
610614

tests/solr_tests/tests/solr_query.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,8 @@ class IttyBittyResult(object):
109109
# Reset to default.
110110
self.sq.set_result_class(None)
111111
self.assertTrue(issubclass(self.sq.result_class, SearchResult))
112+
113+
def test_in_filter_values_list(self):
114+
self.sq.add_filter(SQ(content='why'))
115+
self.sq.add_filter(SQ(title__in=MockModel.objects.values_list('id', flat=True)))
116+
self.assertEqual(self.sq.build_query(), u'(why AND (title:"1" OR title:"2" OR title:"3"))')

tests/whoosh_tests/tests/whoosh_query.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,8 @@ class IttyBittyResult(object):
127127
# Reset to default.
128128
self.sq.set_result_class(None)
129129
self.assertTrue(issubclass(self.sq.result_class, SearchResult))
130+
131+
def test_in_filter_values_list(self):
132+
self.sq.add_filter(SQ(content='why'))
133+
self.sq.add_filter(SQ(title__in=MockModel.objects.values_list('id', flat=True)))
134+
self.assertEqual(self.sq.build_query(), u'(why AND (title:"1" OR title:"2" OR title:"3"))')

0 commit comments

Comments
 (0)