Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular import #165

Open
JoshStegmaier opened this issue Feb 1, 2017 · 1 comment
Open

Circular import #165

JoshStegmaier opened this issue Feb 1, 2017 · 1 comment

Comments

@JoshStegmaier
Copy link
Contributor

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants