ChristopherRabotin / bungiesearch

UNMAINTAINED CODE -- Elasticsearch-dsl-py django wrapper with mapping generator
BSD 3-Clause "New" or "Revised" License
67 stars 20 forks source link

Circular import #165

Open JoshStegmaier opened 7 years ago

JoshStegmaier commented 7 years ago

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.

ChristopherRabotin commented 7 years ago

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