FieldError, But Only In Production

61 views
Skip to first unread message

Rich Jones

unread,
Feb 13, 2014, 6:00:33 AM2/13/14
to django...@googlegroups.com
Hey guys!

I've got a real stumper here. Pulling my hair out over this one, would really appreciate some options!

Anywhere in my application that calls user.get_profile() causes a FieldError.. but only in production. I'm using WSGI and Apache.

When I run locally with:

     python manage.py runserver 0.0.0.0:9999

it works just fine. However, running the exact same code and the exact same database with Apache, I get a 500 and find this in the logs:

     [Wed Feb 12 21:23:21 2014] [error] [client] FieldError: Cannot resolve keyword 'user' into field. Choices are: about_me, about_me_mkd, etc..

(Full traceback: http://pastebin.com/6141pHZ2)

When I run sqlall, there is a users_id entry for the model:

    "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED

What could possibly be happening here? What could the difference between devserver and Apache?

(For reference, this is using Django-Userena 1.0, Django 1.3.7. and Postgres 8.4.)

I've tried a few things I found on the internet:

http://stackoverflow.com/questions/19145787/fielderror-cannot-resolve-keyword-xxxx-into-field
http://chase-seibert.github.io/blog/2010/04/30/django-manytomany-error-cannot-resolve-keyword-xxx-into-a-field.html

Which both suggest that it has something to do with the order of the imports, but I haven't had any success with this approach.

There is an extremely old Django bug seemingly related to this,

https://code.djangoproject.com/ticket/1796

but I don't know how relevant this is, as this is not a ManyToMany problem, because Userena uses a OneToOne field:

    user = models.OneToOneField(User,
                                unique=True,
                                verbose_name=_('user'),
                                related_name='profile')

Can anybody help me? I'm going nuts over here. I just don't know why the behavior would be different for runserver and Apache!

Any ideas?

Thanks so much!,
Rich

Vibhu Rishi

unread,
Feb 13, 2014, 10:21:11 AM2/13/14
to django...@googlegroups.com
Seems to me somewhere in the code it is trying to put user into a field instead of treating it as a table.
Basic sanity checks :
- is the djagno versions on both production and local same ?
- same for wsgi and apache ?
- syncdb worked fine ?

V.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/41e0fdbe-520d-44a4-b3b5-ee4914d0e099%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Simplicity is the ultimate sophistication. - Leonardo da Vinci
Life is really simple, but we insist on making it complicated. - Confucius

Rich Jones

unread,
Feb 13, 2014, 5:17:57 PM2/13/14
to django...@googlegroups.com
Yes, all of these things worked just fine. The code is in the _same location_ on the _same machine_ with the _same settings_ and the _same database_. The only difference is devserver vs Apache.

:(


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/E4UVZHf6kP8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Rich Jones

unread,
Feb 13, 2014, 10:49:58 PM2/13/14
to django...@googlegroups.com
Since this seems to happening at a pretty deep level, would it be uncouth to kick this over do django-dev?

Javier Guerra Giraldez

unread,
Feb 13, 2014, 10:56:16 PM2/13/14
to django...@googlegroups.com
On Thu, Feb 13, 2014 at 5:49 PM, Rich Jones <mise...@gmail.com> wrote:
> Since this seems to happening at a pretty deep level, would it be uncouth to
> kick this over do django-dev?


django-dev is not 'django support, level 2'. it's about the
development of the Django framework. if you have a concrete proposal,
or a full bug report, then by all means take it there. but for usage
questions, this is the right place. also, most (if not all) members
of django-dev also participate actively here.

--
Javier

Rich Jones

unread,
Feb 13, 2014, 11:01:11 PM2/13/14
to django...@googlegroups.com
Ah, okay, noted, although I believe this may be a bug in Django itself but want to exhaust everything before I open a ticket.


Tom Evans

unread,
Feb 13, 2014, 11:01:59 PM2/13/14
to django...@googlegroups.com
On Thu, Feb 13, 2014 at 6:00 AM, Rich Jones <mise...@gmail.com> wrote:
> Hey guys!
>
> I've got a real stumper here. Pulling my hair out over this one, would
> really appreciate some options!
>
> Anywhere in my application that calls user.get_profile() causes a
> FieldError.. but only in production. I'm using WSGI and Apache.
>

Please show how you are doing this.

I suspect mod_wsgi might be using a different version of django,
perhaps one in the system install.

However, that is all just speculative without the config and comparing
it with how you start 'runserver'.

Cheers

Tom

Rich Jones

unread,
Feb 13, 2014, 11:13:05 PM2/13/14
to django...@googlegroups.com

> Please show how you are doing this.

Using mod_wsgi and Apache, using I think a fairly standard .wsgi:

    import os, sys

    path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    if path not in sys.path:
        sys.path.append(path)

    sys.path.append('/srv/myapp')

    os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()

With this in my sites_enabled:

    WSGIScriptAlias / /srv/myapp/myapp/django.wsgi

Also, keep in mind that the application does _run_ with Apache, it is only on calls related to user.get_profile() which causes the problem.

Is there anything else you'd need to know?

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/E4UVZHf6kP8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Rich Jones

unread,
Feb 14, 2014, 12:09:50 AM2/14/14
to django...@googlegroups.com
Said fuck it, gave up and used Nginx + Gunicorn.

We're good now. No idea what the hell was happening, but this works now. Humbling to realize how little I know about the ORM internals.

Thanks for listening,
R

Javier Guerra Giraldez

unread,
Feb 14, 2014, 12:38:51 AM2/14/14
to django...@googlegroups.com
On Thu, Feb 13, 2014 at 7:09 PM, Rich Jones <mise...@gmail.com> wrote:
> We're good now. No idea what the hell was happening, but this works now.
> Humbling to realize how little I know about the ORM internals.


are you using virtualenv? it's possible that mod_wsgi was executing
in a different environment than the test server.

--
Javier

Tom Evans

unread,
Feb 14, 2014, 9:34:36 AM2/14/14
to django...@googlegroups.com
Or mod_wsgi is compiled for a different version of python and thus is
finding completely different libraries.

No matter now...

Rich Jones

unread,
Feb 14, 2014, 10:07:15 AM2/14/14
to django...@googlegroups.com
> are you using virtualenv?  it's possible that mod_wsgi was executing
> in a different environment than the test server.
>

>Or mod_wsgi is compiled for a different version of python and thus is
>finding completely different libraries.

Heh, it was neither of those things. No virtualenv on the machine, so that's the same, and then mod_wsgi was version 2.6 and so is Python.

No matter now, but the mystery remains.



--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/E4UVZHf6kP8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages