MrLoick / app-engine-patch

Automatically exported from code.google.com/p/app-engine-patch
0 stars 0 forks source link

Troubles with CustomUserModel #248

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
***What steps will reproduce the problem?***
1. Update to 1.1RC (from 1.1beta-version)
2. Run server
3. Try to open any page
4. ViewDoesNotExist at /: Tried startpage in module sysapp.views. Error 
was: 'module' object has no attribute 'User'

I've spent a lot of time to find bug.
I've got it!

***Let's exam traceback:***
1. urlresolver import out views.py, where situated view corresponding to 
our url.
2. in views.py we import models.py, where defined our custom user model
3. in models.py we have "from ragendja.auth.google_models import User"
4. in google_models.py we have "from ragendja.auth.models import 
EmailUserTraits"
5. in ragendja.auth.models we have "from django.contrib.auth.models import 
*"
6. in django.contrib.auth.models we have code, that try to import out 
custom user model. But look at step 2 — we are alredy in the process of 
importing _this_ module with model! at that line when it is still not 
defined the custom user class. Loop here! We've got an error

***So, why it worked earlier?***
'Cause there were earlier import of django.contrib.auth.views (which 
imports model, where custom user model setuped) in file 
ragendja.middleware:

line 6: from django.contrib.auth.views import redirect_to_login

In 1.1RC this import statement called only if accessed page are in 
settings.LOGIN_REQUIRED_PREFIXES.

I've returned this import to head of file and problem gone. It's ugly fix.

So, i think, to really solve this problem, you should import 
django.contrib.auth.models as early as possible in app-engine-patch 
initialization.

Hopefully, the problem is clear.
If you have any questions - I am ready to answer them

Original issue reported on code.google.com by denya....@gmail.com on 15 Dec 2009 at 7:21