First time here? Check out the FAQ!

Revision history  [back]

Askbot fails when using Nginx+Gunicorn

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.

Askbot fails when using Nginx+Gunicorn

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.

Askbot fails when using Nginx+Gunicorn

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