Askbot fails when using Nginx+Gunicorn

  • retag add tags

In my attempt to integrate Askbot with an already running Django site, I had to make it run under current setup (nginx+gunicorn), but it keeps failing, been trying to figure out what's wrong but now I'm pretty much clueless. There are some speculation about the python paths, gunicorn workers (gevent) and other stuff, but even after trying to change all of them, it still failed. The error was:

'NoneType' object has no attribute 'field_name'

Here's the complete stack trace: https://gist.github.com/4363587

This is not happening when I'm running the dev server (manage.py runserver).

Appreciate any help and thanks for making such an awesome Q&A Platform!.

Update This seems to be triggered by Group model, a simple query would break the script with the same error:

from askbot.models.user import Group
Group.objects.filter(user=[any_user])

The same code would run just fine from ./manage.py shell

Update This error is somehow related to fetching ManyToMany relationship. To trigger it, try running this on dev and gunicorn:

user = User.objects.get(username='admin') # for example
user.get_primary_group()

When running that code on dev, I get fine result, however gunicorn shows:

'NoneType' object has no attribute 'field_name'

If you follow the stack trace, you'll get to this function to map m2m attribute in Django, I tried to inject this to compare the result of f.rel.to == related.model for get_primary_group(), here's what I get with dev server:

<django.contrib.auth.models.User> == <django.contrib.auth.models.User>

And here's what I get with gunicorn:

<django.contrib.auth.models.User> != <django.contrib.auth.models.User>

If I use dir() on both scenarios, it turned out that the User model on dev server has a lot of properties and map the complete list of related_name (my apps and askbot), in gunicorn, there is just default User properties such as change_password.

You can also try to run this code in both dev and gunicorn, the result on both server will be different:

from django.contrib.auth.models import User
print dir(User.groups.field.rel.through._meta.fields[1].rel.to) # Will return User model

But strangely, this code shows fine and same result on both server:

from django.contrib.auth.models import User
print dir(User)

First I thought it was a migration problem, but I already triggered migration many times and checked my migration list, it was completed.

kecebongsoft's avatar
31
kecebongsoft
asked 2012-12-23 08:11:32 -0500, updated 2012-12-26 08:39:25 -0500
edit flag offensive 0 remove flag close merge delete

Comments

Looks like your database is not migrated. Try python manage.py migrate.

Evgeny's avatar Evgeny (2012-12-26 07:29:30 -0500) edit

@Evgeny I triggered migrations many times before and checked my migration list, it was all completed, I added more details in the question. Thanks!.

kecebongsoft's avatar kecebongsoft (2012-12-26 08:40:20 -0500) edit

For the get_primary_group() usage example - did you import user model from askbot.models or django.contrib.auth.models ?

Evgeny's avatar Evgeny (2012-12-26 08:57:03 -0500) edit

I use django.contrib.auth.models, the reason I use that example is because that particular code is also exist in Askbot template.

kecebongsoft's avatar kecebongsoft (2012-12-26 09:12:07 -0500) edit

Try importing from askbot.models, that's where the methods are added to the user model. Can you email me at support@askbot.com I'll try to help you further.

Evgeny's avatar Evgeny (2012-12-26 09:34:16 -0500) edit
add a comment see more comments