Skip to content

Commit af6b41f

Browse files
henriquechehadacdha
authored andcommitted
fix: attribute resolution on models which have a property named all (django-haystack#1405)
Thanks to Henrique Chehad (@henriquechehad) for the patch Closes django-haystack#1404
1 parent e7e83ad commit af6b41f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

haystack/fields.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from haystack.exceptions import SearchFieldError
1010
from haystack.utils import get_model_ct_tuple
1111

12+
from inspect import ismethod
13+
1214

1315
class NOT_PROVIDED:
1416
pass
@@ -110,7 +112,6 @@ def resolve_attributes_lookup(self, current_objects, attributes):
110112

111113
if len(attributes) > 1:
112114
current_objects_in_attr = self.get_iterable_objects(getattr(current_object, attributes[0]))
113-
114115
return self.resolve_attributes_lookup(current_objects_in_attr, attributes[1:])
115116

116117
current_object = getattr(current_object, attributes[0])
@@ -148,7 +149,10 @@ def get_iterable_objects(cls, current_objects):
148149

149150
if hasattr(current_objects, 'all'):
150151
# i.e, Django ManyToMany relationships
151-
current_objects = current_objects.all()
152+
if ismethod(current_objects.all):
153+
return current_objects.all()
154+
return []
155+
152156
elif not hasattr(current_objects, '__iter__'):
153157
current_objects = [current_objects]
154158

0 commit comments

Comments
 (0)