Authentification - Django - Query mongoengine.django.auth.UserManager

85 views
Skip to first unread message

christophe de saint leger

unread,
May 22, 2013, 11:04:12 AM5/22/13
to mongoeng...@googlegroups.com
I all, 
i don't know if this problem is from mongoengine ( link width Django "Authentification" ) but i think there are relation .

I have created a model ( CreaviUser )  who derivate from User model. 

Each request must be authentificated, by a middleware ( this is a simple test is_authenticated() ) , but when i refresh or navigate on my website, sometimes i am redirected to my login form . And if i refresh again , i return on my website ! 

I checked the logs of mongodb : 

Wed May 22 16:09:25.632 [conn1036] query creaboard.user query: { _id: ObjectId('5194922d88a53d4da3a2f6ce'), _cls: { $in: [ "User" ] } } ntoreturn:1 ntoskip:0 nscanned:0 keyUpdates:0 locks(micros) r:83 nreturned:0 reslen:20 0ms
Wed May 22 16:09:25.643 [conn1033] query creaboard.user query: { _id: ObjectId('5194922d88a53d4da3a2f6ce'), _cls: { $in: [ "User", "User.CreaviUser" ] } } ntoreturn:1 ntoskip:0 nscanned:3 keyUpdates:0 locks(micros) r:141 nreturned:1 reslen:548 0ms

Sometimes the query is different 

ok   ->  $in: [ "User", "User.CreaviUser" ]
Fail ->  $in: [ "User" ]


Have you an idea of the problem?

Ch.

My CreaviUser Model: 
# -*- coding:utf-8 -*-
from mongoengine import *
from mongoengine.django.auth import User,UserManager
import datetime

class CreaviUser(User):
    """
    Surcharge de l'utilisateur standard
    """
    username           = StringField(max_length=50,required=True)
    is_admin           = BooleanField(default=False)
    nocentre           = IntField(required=True)
    centre             = StringField(max_length=50, required=True)
    adresse            = StringField(max_length=100, required=True)
    adresse2           = StringField(max_length=100, required=False)
    cp                 = StringField(max_length=5, required=True)
    ville              = StringField(max_length=50, required=True)
    pays               = StringField(max_length=50,default='FRANCE',required=True)
    telephone          = StringField(max_length=30, required=False)
    fax                = StringField(max_length=30, required=False)
    site               = URLField()
    mail               = EmailField()
    date               = DateTimeField(default=datetime.datetime.now, required=True)
    # Use UserManager to get the create_user method, etc.
    objects = UserManager()

christophe de saint leger

unread,
May 22, 2013, 2:36:17 PM5/22/13
to mongoeng...@googlegroups.com
Ok , when i test with a single process (uwsgi) , it work fine ...
And i have tested with Django 1.4 with multi process ... it work fine too ...

i'm lost :(

christophe de saint leger

unread,
May 23, 2013, 4:34:10 AM5/23/13
to mongoeng...@googlegroups.com
I do not understand why sometimes the application does not use the model derived.
Yet it is referenced in the _cls field.

Any idea?


Ch.


Le mercredi 22 mai 2013 17:04:12 UTC+2, christophe de saint leger a écrit :

Ross Lawley

unread,
May 23, 2013, 4:57:21 AM5/23/13
to mongoeng...@googlegroups.com
Without producing a reproducible test case, its hard to determine the cause.  

What checks that the user is logged in?  Child classes should return when queried from the parent class.

Also what version of MongoEngine is this?


--
You received this message because you are subscribed to the Google Groups "MongoEngine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoengine-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

christophe de saint leger

unread,
May 23, 2013, 5:21:37 AM5/23/13
to mongoeng...@googlegroups.com
I use mongoengine : mongoengine==0.8.1 and Django 1.5.1

The problem appear only when i use multi process uwsgi.

i use a middleware to check if my user is logged :

from django.http import HttpResponse,HttpResponseRedirect

class AuthenticationMiddleware(object):
   
    _LOGIN_PATH = "/accounts/login_view/"
   
    def process_request(self, request):

        if (request.path != self._LOGIN_PATH) and not request.is_ajax():
            if not request.user.is_authenticated():
                return HttpResponseRedirect( self._LOGIN_PATH+'?next=%s' % request.path)
        return None


My child class only serves to enrich the model User.

Ch

christophe de saint leger

unread,
May 23, 2013, 8:06:20 AM5/23/13
to mongoeng...@googlegroups.com
I tested uwsgi multi threaded mode, with a single process, and it works perfectly.
Same with gunicorn.

There must have global data is not shared between processes.

so I think mongoengine is not responsible for this bug ..
Sorry for the inconvenience.

good day,

Ch.
Reply all
Reply to author
Forward
0 new messages