8000 Fix RelatedSearchQueryset.load_all() truncating results · django-haystack/django-haystack@0461071 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0461071

Browse files
committed
Fix RelatedSearchQueryset.load_all() truncating results
Fixes #2011
1 parent 7d139b4 commit 0461071

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

haystack/query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def post_process_results(self, results):
194194
# No objects were returned -- possible due to SQS nesting such as
195195
# XYZ.objects.filter(id__gt=10) where the amount ignored are
196196
# exactly equal to the ITERATOR_LOAD_PER_QUERY
197-
del self._result_cache[: len(results)]
198-
self._ignored_result_count += len(results)
199-
break
197+
del self._result_cache[: 1]
198+
self._ignored_result_count += 1
199+
continue
200200

201201
to_cache.append(result)
202202

test_haystack/solr_tests/test_solr_backend.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,19 @@ def test_related_load_all_queryset(self):
12201220
self.assertEqual([obj.object.id for obj in sqs], list(range(11, 24)))
12211221
self.assertEqual([obj.object.id for obj in sqs[10:20]], [21, 22, 23])
12221222

1223+
def test_related_load_all_with_empty_model_results(self):
1224+
another_index = SolrAnotherMockModelSearchIndex()
1225+
another_index.update("solr")
1226+
self.ui.build(indexes=[self.smmi, another_index])
1227+
1228+
sqs = self.rsqs.order_by('id')
1229+
assert len(list(sqs)) == 25
1230+
sqs = sqs.all().load_all_queryset(AnotherMockModel, AnotherMockModel.objects.none())
1231+
sqs = sqs.load_all()
1232+
# two AnotherMockModel objects are skipped, so only 23 results now
1233+
# (but those results are still present and weren't skipped)
1234+
assert len(list(sqs)) == 23
1235+
12231236
def test_related_iter(self):
12241237
reset_search_queries()
12251238
self.assertEqual(len(connections["solr"].queries), 0)

0 commit comments

Comments
 (0)
0