I am using django-haystack 2.4.1 version with elasticsearch and django 1.8.11 I am having issues while updating the index with remove parameter. If some of my models get deleted and then if I run
./manage.py update_index --remove
I get the error AttributeError: Nonetype object has no attribute '_meta'
I checked the trace and found out that the error is coming from default_get_identifier method
default_get_identifier
return u"%s.%s" % (get_model_ct(obj_or_string),
Here as the model is deleted already, get_model_ct returns the attribute error.
Then I found out about the HAYSTACK_IDENTIFIER_METHOD parameter, so I thought of defining my own method which is mentioned below
def getHaystackIdentifier(obj_or_string):
return (str(obj_or_string)+"."+str(obj_or_string._get_pk_val()))
But the fundamental problem remains same as obj_or_string model is already deleted from the database,
How can I get the identifier of the stale records and delete them from index?
Shouldn't haystack automatically delete the records if model is not found corresponding to that? I am not sure if I am missing something here
I was able to solve this issue. The problem was HAYSTACK_ID_FIELD defined in django settings file as my field name (id) was colliding with the default haystack field. http://django-haystack.readthedocs.io/en/v2.4.1/settings.html#haystack-id-field
I changed my field name to something else and removed this setting and everything seems to be working fine. Note that even if I change my field name but don't remove this entry from settings file, it still gives me error.
Check the full trace of this error on github issues here https://github.com/django-haystack/django-haystack/issues/1380