I'm trying to implement a stand-alone python script to check a session
cookie for group authorization. I cribbed from the auth and session
middleware, so I could take the sessionid from the cookie, look up the
session, look up the user, and get the list of groups.

This all basically works, except for the very first time a session is
seen. The first lookup always fails. I know the session is good (a
call to a django view via @login_required, for example, works fine).

I'm expecting this is some problem with a cache, or evaluation order,
such that my script doesn't have the latest info from the db until
I've queried it once. Anyone have a clue? Here's what the auth
checking routine looks like:


def authorized(session_id, group):
    ss = engine.SessionStore(session_id)
    session=ss.load()
    try:
        user_id = session[SESSION_KEY]
        backend_path = session[BACKEND_SESSION_KEY]
        backend = load_backend(backend_path)
        user = backend.get_user(user_id) or AnonymousUser()
    except KeyError:
        user = AnonymousUser()
    return user.groups.filter(name=group).count()


It's called from a "while 1" loop in a script that never exits. The
first time a session cookie goes through this routine, it always
fails. Second, and subsequent times work.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to