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

Using non numeric primary keys #297

Open
girardinsamuel opened this issue Aug 31, 2022 · 1 comment
Open

Using non numeric primary keys #297

girardinsamuel opened this issue Aug 31, 2022 · 1 comment

Comments

@girardinsamuel
Copy link

Hi !

I am using Django Hash ID for my primary keys of my models (https://github.com/nshafer/django-hashid-field).
When building indexes of the models django-watson is expecting numeric primary keys. Would it be possible to handle both string and numeric primary keys ? Or do you advise a better strategy for using django-watson in my case ?

Here is the error log when running buildwatson command:

Traceback (most recent call last):
  File "/Users/johndoe/repos/myproject/application/./manage.py", line 22, in <module>
    main()
  File "/Users/johndoe/repos/myproject/application/./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/django/core/management/base.py", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/watson/management/commands/buildwatson.py", line 187, in handle
    refreshed_model_count += rebuild_index_for_model(
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/watson/management/commands/buildwatson.py", line 74, in rebuild_index_for_model
    _bulk_save_search_entries(iter_search_entries(), batch_size=batch_size_)
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/watson/search.py", line 207, in _bulk_save_search_entries
    search_entry_batch = list(islice(search_entries, 0, batch_size))
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/watson/management/commands/buildwatson.py", line 47, in iter_search_entries
    for search_entry in search_engine_._update_obj_index_iter(obj):
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/watson/search.py", line 510, in _update_obj_index_iter
    object_id_int, search_entries = self._get_entries_for_obj(obj)
  File "/Users/johndoe/.pyenv/versions/myproject_application/lib/python3.9/site-packages/watson/search.py", line 480, in _get_entries_for_obj
    object_id_int = int(obj.pk)

ValueError: invalid literal for int() with base 10: 'OzZYA4y3q9X5VMGg'

Here OzZYA4y3q9X5VMGg is the hash id of my model (which is the primary key).

Thank you very much 🙏 !

@etianen
Copy link
Owner

etianen commented Sep 10, 2022 via email

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

2 participants