Skip to content

Commit 64d2bc0

Browse files
authored
Merge pull request #2012 from koordinates/fix-load-all-with-missing-model-results
Fix RelatedSearchQueryset.load_all() truncating results
2 parents 7d139b4 + d04a584 commit 64d2bc0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,21 @@ 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(
1231+
AnotherMockModel, AnotherMockModel.objects.none()
1232+
)
1233+
sqs = sqs.load_all()
1234+
# two AnotherMockModel objects are skipped, so only 23 results now
1235+
# (but those results are still present and weren't skipped)
1236+
assert len(list(sqs)) == 23
1237+
12231238
def test_related_iter(self):
12241239
reset_search_queries()
12251240
self.assertEqual(len(connections["solr"].queries), 0)

0 commit comments

Comments
 (0)