1👍
Move the import into the function.
edit: submitted this a bit prematurely 😛
When your imports are at the top of a file, they are executed as soon as that file is imported. That causes this type of error.
You can limit your imports to a function’s scope to avoid this issue.
When you run into this issue, you should at least double check that your architecture is really appropriate. It is sometimes (but certainly not always) an indication that your architecture can be improved.
I find that you can usually move the function from the model to helpers, and make the first argument of the function be an instance of the model. That way, you’ll just have a helper importing a helper.
(second edit: removed example code, which made no sense)
Source:stackexchange.com