Hi Marin,

we've found a temporary solution for this problem until they fix it in 
web2py.

Here are some code excerpts from gluon/tools.py

def login_user(self, user):
    """
    login the user = db.auth_user(id)
    """
    from gluon.settings import global_settings
    if global_settings.web2py_runtime_gae:
        user = Row(self.db.auth_user._filter_fields(user, id=True))
        delattr(user,'password')
    else:
        user = Row(user)
        for key,value in user.items():
        if callable(value) or key=='password':
            delattr(user,key)
    current.session.auth = Storage(
        user = user,
        last_visit=current.request.now,
        expiration=self.settings.expiration,
        hmac_key=web2py_uuid())
    self.user = user
    self.update_groups()

def update_groups(self):
        if not self.user:
            return
        user_groups = self.user_groups = {}
        if current.session.auth:
            current.session.auth.user_groups = self.user_groups
        table_group = self.table_group()
        table_membership = self.table_membership()
        memberships = self.db(
            table_membership.user_id == self.user.id).select()
        for membership in memberships:
            group = table_group(membership.group_id)
            if group:
                user_groups[membership.group_id] = group.role



Function update_groups raises the error, we don't know why.
It stores the user's groups in a dict, this dict is used only by wiki 
functions in gluon/tools.py.

has_membership doesn't use this dict, it creates a new select query.

So the simplest solution is to comment out or remove self.update_groups() 
from login_user function.

Or like we did, create a new Auth class with an empty load_user function.

modules/auth2.py

#!/bin/python
# -*- coding: utf-8 -*-

from gluon.tools import Auth

class Auth2(Auth):

    def __init__(self, 
                environment, 
                db=None, 
                controller='default'):

        super(Auth2, self).__init__(environment, db, controller)

    def update_groups(self):
        return



And in db.py

#auth = Auth(db)
exec('from applications.%s.modules.auth2 import Auth2' % request.application
)
auth=Auth2(globals(),db)

Regards,
Oliver


On Saturday, March 2, 2013 8:55:17 PM UTC+1, Marin Pranjić wrote:
>
> This happened to an user multiple times. No idea why it happens.
>
> Error ticket doesn't show much, this is everything I can get from there:
>
> Traceback (most recent call last):
>  File "/home/www-data/web2py/gluon/main.py", line 571, in wsgibase
>  session._try_store_in_cookie_or_file(request, response)
>  File "/home/www-data/web2py/gluon/globals.py", line 738, in 
> _try_store_in_cookie_or_file
>  self._try_store_in_file(request, response)
>  File "/home/www-data/web2py/gluon/globals.py", line 745, in 
> _try_store_in_file
>  if not response.session_id or self._forget or self._unchanged():
>  File "/home/www-data/web2py/gluon/globals.py", line 700, in _unchanged
>  session_pickled = cPickle.dumps(dict(self))
>  File "/usr/lib/python2.7/copy_reg.py", line 74, in _reduce_ex
>  getstate = self.__getstate__
>  File "/home/www-data/web2py/gluon/dal.py", line 7355, in __getattr__
>  self.__allocate()
>  File "/home/www-data/web2py/gluon/dal.py", line 7350, in __allocate
>  raise RuntimeError, "Using a recursive select but encountered a broken 
> reference: %s %d"%(self._table, int(self))
> RuntimeError: Using a recursive select but encountered a broken reference: 
> auth_group 5
>
>
>
> However, auth_group record with id=5 exists. I have no idea why it raises an 
> error.
>
> I'm using web2py 2.2.1, this is production instance so I can't test with 
> other versions right now.
>
>
> Marin
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to