1. Kai Diefenbach
  2. django_permissions
  3. Issues
Issue #3 resolved

get_roles from permissions.utils fails when obj is None

Jakub Wiśniowski
created an issue

The problem is that when you call: {{{

!python

from permissions.utils import get_roles roles = get_roles(some_user) }}}

you will get: AttributeError: None object has no attribute id.

This is because get_roles calls get_local_roles with obj == None. See below (http://bitbucket.org/diefenbach/django-permissions/src/tip/permissions/utils.py#cl-198):

{{{

!python

if obj is not None:
    roles.extend(get_local_roles(obj, principal))

if isinstance(principal, User):
    for group in principal.groups.all():
        roles.extend(get_local_roles(obj, group))
        roles.extend(get_roles(group))

}}}

so it should be like:

{{{

!python

if obj is not None:
    roles.extend(get_local_roles(obj, principal))

if isinstance(principal, User):
    for group in principal.groups.all():
        if obj is not None:
            roles.extend(get_local_roles(obj, group))
        roles.extend(get_roles(group))

}}}

Comments (1)

  1. Log in to comment