Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_index --remove disregards HAYSTACK_ID_FIELD #1667

Open
2 tasks done
butteredtoast opened this issue Mar 16, 2019 · 0 comments
Open
2 tasks done

update_index --remove disregards HAYSTACK_ID_FIELD #1667

butteredtoast opened this issue Mar 16, 2019 · 0 comments

Comments

@butteredtoast
Copy link

butteredtoast commented Mar 16, 2019

  • Tested with the latest Haystack release
  • Tested with the current Haystack master branch

Expected behaviour

It should be possible to clear indexes that do not use the default haystack ID.

Actual behaviour

Fails with the following error:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/etc/cravus/env/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/etc/cravus/env/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/etc/cravus/env/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/etc/cravus/env/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/etc/cravus/env/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 183, in handle
    return super(Command, self).handle(*items, **options)
  File "/etc/cravus/env/lib/python3.4/site-packages/django/core/management/base.py", line 548, in handle
    label_output = self.handle_label(label, **options)
  File "/etc/cravus/env/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 188, in handle_label
    self.update_backend(label, using)
  File "/etc/cravus/env/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 289, in update_backend
    backend.remove(rec_id, commit=self.commit)
  File "/etc/cravus/env/lib/python3.4/site-packages/haystack/backends/elasticsearch_backend.py", line 196, in remove
    doc_id = get_identifier(obj_or_string)
  File "/etc/cravus/env/lib/python3.4/site-packages/haystack/utils/__init__.py", line 37, in default_get_identifier
    return u"%s.%s" % (get_model_ct(obj_or_string), obj_or_string._get_pk_val())
  File "/etc/cravus/env/lib/python3.4/site-packages/haystack/utils/__init__.py", line 80, in get_model_ct
    return "%s.%s" % get_model_ct_tuple(model)
  File "/etc/cravus/env/lib/python3.4/site-packages/haystack/utils/__init__.py", line 74, in get_model_ct_tuple
    return (model._meta.app_label, model._meta.model_name)
AttributeError: 'int' object has no attribute '_meta'

Steps to reproduce the behaviour

  1. Add HAYSTACK_ID_FIELD='haystack_id' # or some other name in the settings file
  2. Create object and index, with the id field being used
  3. Remove object
  4. Run python manage.py update_index --remove

Configuration

  • Haystack version: 2.8.1

On account of the fact that haystack provisions the settings option HAYSTACK_ID_FIELD, this should be taken into account when attempting to remove items from the index. However, this is not presently being done, as seen here:

index_pks = index_pks.values_list('pk', 'id')

The fix would be:

from haystack.constants import ID
...

index_pks = index_pks.values_list('pk', ID)

This issue is an extension of a previous addressed issue #1323

@butteredtoast butteredtoast changed the title update_index --remove disregards HAYSTACK_ID_FIELD update_index --remove disregards HAYSTACK_ID_FIELD Mar 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant