django-haystack / django-haystack/django-haystack

Allow HAYSTACK_SIGNAL_PROCESSOR Class to Import Models

Open
#1,212 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently, if you use the HAYSTACK_SIGNAL_PROCESSOR function to set to a class which imports a model, then you can get ciruclar imports. This was also reported here:
http://stackoverflow.com/questions/17049426/importerror-when-using-haystack-2-0-0-with-django-1-5-and-gunicorn-wsgi

It would be nice if our signal processors could import our models.

I think the issue is in __init__.py here:

# Setup the signal processor.
signal_processor_path = getattr(settings, 'HAYSTACK_SIGNAL_PROCESSOR', 
   'haystack.signals.BaseSignalProcessor')
signal_processor_class = loading.import_class(signal_processor_path)
signal_processor = signal_processor_class(connections, connection_router)

We should not be importing or instantiating this class within __init__.py, otherwise it can easily cause circular imports. Instead, we should try to lazy load it.

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 in init.py at the signal processor setup and read how loading.import_class and instantiation are performed. Reproduce the configuration with a HAYSTACK_SIGNAL_PROCESSOR class that imports a model, then trace the circular import. Done means signal processors can import models without causing circular imports during initialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend
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.