Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django user get_all_permissions() is empty while user_permissions is set

I added some permissions to a user via the admin interface.

From some reason all the perm functions fail, e.g

>>> user.get_all_permissions() set([]) 

But accessing the table directly, works:

>>> user.user_permissions.all() (list of permissions as expected) 

What can cause the "get_all_permissions" (and all the perm functions like has_perm()) to fail ?

Thanks

like image 293
Boris Avatar asked Jan 17 '10 13:01

Boris


1 Answers

had the same problem. I am guessing that at some point you have used a self-crafted AUTHENTICATION_BACKEND? Most examples on the net of this (INCLUDING THE DJANGO 1.0 DOCUMENTATION!) don't mention that the Backends are responsible for permissions handling as well.

However, no biggie: In whatever backend file your code resides, include this import:

from django.contrib.auth.backends import ModelBackend 

Then make sure the Backend you wrote extends ModelBackend, e.g.:

class EmailBackend(ModelBackend): 

Should be fine.

like image 53
Mark Henwood Avatar answered Oct 05 '22 23:10

Mark Henwood