Skip to content

Commit c35d0ce

Browse files
committed
Deprecated get_queryset & fixed how indexing happens. Thanks to Craig de Stigter & others for the report!
1 parent 78adc9a commit c35d0ce

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

docs/migration_from_1_to_2.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ set the ``HAYSTACK_DOCUMENT_FIELD`` setting. For example::
169169
HAYSTACK_DOCUMENT_FIELD = 'pink_polka_dot'
170170

171171
Finally, the ``index_queryset`` method should supplant the ``get_queryset``
172-
method. This was present in the Haystack 1.2.X series & ``get_queryset`` will
173-
continue to work for backward-compatibility.
172+
method. This was present in the Haystack 1.2.X series (with a deprecation warning
173+
in 1.2.4+) but has been removed in Haystack v2.
174174

175175
Finally, if you were unregistering other indexes before, you should make use of
176176
the new ``HAYSTACK_EXCLUDED_INDEXES`` setting. It should be a list of strings

docs/searchindex_api.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,6 @@ Get the default QuerySet to index when doing a full update.
380380

381381
Subclasses can override this method to avoid indexing certain objects.
382382

383-
``get_queryset``
384-
----------------
385-
386-
.. method:: SearchIndex.get_queryset(self)
387-
388-
Alias of ``SearchIndex.index_queryset`` for backwards compatibility.
389-
390383
``read_queryset``
391384
-----------------
392385

haystack/indexes.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ def index_queryset(self):
123123
"""
124124
return self.get_model()._default_manager.all()
125125

126-
def get_queryset(self):
127-
"""
128-
Alias of index_queryset for backwards compatibility.
129-
"""
130-
return self.index_queryset()
131-
132126
def read_queryset(self):
133127
"""
134128
Get the default QuerySet for read actions.

haystack/management/commands/update_index.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
import os
3+
import warnings
34
from optparse import make_option
45
from django.conf import settings
56
from django.core.exceptions import ImproperlyConfigured
@@ -58,12 +59,20 @@ def build_queryset(index, model, age=DEFAULT_AGE, verbosity=1):
5859
if verbosity >= 2:
5960
print "No updated date field found for '%s' - not restricting by age." % model.__name__
6061

61-
if not hasattr(index.index_queryset(), 'filter'):
62-
raise ImproperlyConfigured("The '%r' class must return a 'QuerySet' in the 'get_queryset' method." % index)
62+
index_qs = None
63+
64+
if hasattr(index, 'get_queryset'):
65+
warnings.warn("'SearchIndex.get_queryset' was deprecated in Haystack v2. Please rename the method 'index_queryset'.")
66+
index_qs = index.get_queryset()
67+
else:
68+
index_qs = index.index_queryset()
69+
70+
if not hasattr(index_qs, 'filter'):
71+
raise ImproperlyConfigured("The '%r' class must return a 'QuerySet' in the 'index_queryset' method." % index)
6372

6473
# `.select_related()` seems like a good idea here but can fail on
6574
# nullable `ForeignKey` as well as what seems like other cases.
66-
return index.index_queryset().filter(**extra_lookup_kwargs).order_by(model._meta.pk.name)
75+
return index_qs.filter(**extra_lookup_kwargs).order_by(model._meta.pk.name)
6776

6877

6978
def do_update(backend, index, qs, start, end, total, verbosity=1):

tests/core/tests/indexes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ def test_proper_fields(self):
196196
def test_index_queryset(self):
197197
self.assertEqual(len(self.cmi.index_queryset()), 3)
198198

199-
def test_get_queryset(self):
200-
self.assertEqual(len(self.cmi.get_queryset()), 3)
201-
202199
def test_read_queryset(self):
203200
self.assertEqual(len(self.cmi.read_queryset()), 2)
204201

0 commit comments

Comments
 (0)