django-haystack / django-haystack/django-haystack

build_solr_schema field type conflict

Open
#1,062 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi, I have some indexes with same field for different models and different types

Example:

class CompanyIndex(indexes.SearchIndex, indexes.Indexable):
        country = indexes.IntegerField(null=True)

class OrgIndex(indexes.SearchIndex, indexes.Indexable):
    country = indexes.MultiValueField(null=True)

the result of build schema will be:
< field name="country" type="text_en" indexed="true" stored="true" multiValued="true" / >

one field with multivalue field set to True ...

and as a result I get an exception

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/bin/tpp/lib/python3.3/site-packages/haystack/query.py", line 266, in __getitem__
    self._fill_cache(start, bound)
  File "/usr/local/bin/tpp/lib/python3.3/site-packages/haystack/query.py", line 166, in _fill_cache
    results = self.query.get_results(**kwargs)
  File "/usr/local/bin/tpp/lib/python3.3/site-packages/haystack/backends/__init__.py", line 644, in get_results
    self.run(**kwargs)
  File "/usr/local/bin/tpp/lib/python3.3/site-packages/haystack/backends/solr_backend.py", line 697, in run
    results = self.backend.search(final_query, **search_kwargs)
  File "/usr/local/bin/tpp/lib/python3.3/site-packages/haystack/backends/__init__.py", line 34, in wrapper
    return func(obj, query_string, *args, **kwargs)
  File "/usr/local/bin/tpp/lib/python3.3/site-packages/haystack/backends/solr_backend.py", line 133, in search
    return self._process_results(raw_results, highlight=kwargs.get('highlight'), result_class=kwargs.get('result_class', SearchResult), distance_point=kwargs.get('distance_point'))
  File "/usr/local/bin/tpp/lib/python3.3/site-packages/haystack/backends/solr_backend.py", line 382, in _process_results
    additional_fields[string_key] = index.fields[string_key].convert(value)
  File "/usr/local/bin/tpp/lib/python3.3/site-packages/haystack/fields.py", line 232, in convert
    return int(value)
TypeError: int() argument must be a string or a number, not 'list'

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 by tracing schema generation for build_solr_schema, then inspect haystack/backends/solr_backend.py and haystack/fields.py where the traceback reaches result conversion. Check existing tests around schema fields and Solr result processing; done means indexes sharing a field name with different types no longer produce an incompatible schema or a list-to-integer conversion failure.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.