django-haystack / django-haystack/django-haystack

Use of deferred fields in index_queryset breaks search

Open
#405 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs review
Dominant language
Python
Stars
3.7k
Forks
1.3k
Avg merge
3h 18m
Merged PRs (30d)
3

Description

In my index's index_queryset method I use MyModel.objects.only() to limit the amount of data Haystack has to pull from the database. This works, but then the models are stored in Solr with a "django_ct" field with a mangled name such as "music.track_deferred_album_purchase_only_can_purchase_13e21ebf5814beb5662fa2c54730ecc1".

Later, when I go do a search with SearchQuerySet(), Haystack filters on "django_ct=music.track". Since all the models were stored with a different "django_ct" field, the search returns no results. The problem is that Haystack uses obj._meta.module_name to figure out the value of "django_ct", but for some reason, when using only() in QuerySets, django stores a different name for module_name.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the index_queryset path and the code that generates the django_ct value, then trace how QuerySet.only() changes _meta.module_name. Reproduce the deferred-field case and compare indexing with SearchQuerySet filtering. Done means deferred querysets retain the normal content-type value and indexed records remain searchable.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.