0

I am running django 1.5.5 with uwsgi. I am getting this exception in uwsgi, everything works fine with runserver:

ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e)) django.core.exceptions.ImproperlyConfigured: Error importing middleware mymodule.middleware: "cannot import name MyClass"

Here is the really strange part:

When I add this at the top of mymodule.middleware, uwsgi runs just fine: import pdb

I don't need to enter the debugger, just import the pdb module. pdb is not referenced in the middleware. In fact I have searched the entire repository and it isn't referenced anywhere.

My first thought was some sort of circular import, but I can't find it. Any other ideas?

Update: This was indeed a circular import, in one of the imported modules. I still have no idea why importing pdb made any difference. If anyone can shed light on that, I would like to better understand what was going on.

AgDude
  • 1,167
  • 1
  • 10
  • 27
  • Could you please share the source of the `mymodule.middleware` module? – piotrekw Apr 30 '14 at 12:47
  • Sorry, I cannot share the source of that module. In the process response method, it imports a celery task mytask from a tasks.py file, then if certain criteria are met it calls mytask.delay() – AgDude Apr 30 '14 at 12:57
  • What's all imported in the mymodule.middleware module at the top of the file? – schillingt Apr 30 '14 at 13:42
  • 1
    It's hard to help you without looking at the code. If MyClass is a model, then you have a whole category of possible issues. Try to simplify your middleware. For example, remove everything that may be causing the error and try again. If it works, put back things you previously removed - step by step - and try again. – piotrekw Apr 30 '14 at 13:42
  • I would be glad to accept an answer that discussed in general why importing pdb would make a difference. I am an experienced python programmer, and this seems like strange behavior to me. You need to trust me that pdb is not referenced anywhere in my code. I searched the entire codebase for "pdb\." and found nothing. – AgDude Apr 30 '14 at 13:59

0 Answers0