bungiesearch icon indicating copy to clipboard operation
bungiesearch copied to clipboard

Circular import

Open JoshStegmaier opened this issue 9 years ago • 1 comments

I'm having an issue with circular imports. As described in the documentation, I have a ModelIndex defined for a model in app_name/bungiesearch_indices.py. I necessarily import the model in bungiesearch_indices.py.

Also as described in the documentation, I do from "bungiesearch.managers import BungiesearchManager" in app_name/models.py and set objects = BungiesearchManager() on the relevant model.

In my settings.py, I have BUNGIESEARCH setting with an INDICES key that points to 'appname.bungiesearch_indices'.

When my project loads, my model is imported, which tries to import BungiesearchManager, which (by loading Bungiesearch in bungiesearch/init.py) tries to load the indices. Trying to load the indices requires loading my model, which requires BungiesearchManager to be imported, etc.

If I remove the BungiesearchManager import (and the objects = BungiesearchManager()), everything loads fine, but then I can't use BungiesearchManager on the models.

Is there a solution to this? Normal solutions to circular imports (like importing inside a function) don't work in this case.

JoshStegmaier avatar Feb 01 '17 11:02 JoshStegmaier

What version of Django are you using? Bungiesearch does not work with Django >= 1.10.

Can you also provide the tree of your project just to have a better idea as to why this circular import happens? Thanks

ChristopherRabotin avatar Feb 04 '17 03:02 ChristopherRabotin