From 6f2c0dbf4d9180641febdf42c3f3f0c39bcb0e5a Mon Sep 17 00:00:00 2001 From: Mark Davidoff Date: Sun, 28 Oct 2018 14:12:39 -0700 Subject: [PATCH] permissions must return a boolean `x and y` actually returns object y when both are true. the means P & IsAuthenticated will fail with TypeError: unsupported operand type(s) for &: 'instance' and 'bool' as IsAuthenticated now returns a CallableBool which does not overload __ror__ --- rest_framework/permissions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rest_framework/permissions.py b/rest_framework/permissions.py index dfe89ed2a..d1e84e088 100644 --- a/rest_framework/permissions.py +++ b/rest_framework/permissions.py @@ -110,7 +110,7 @@ class IsAuthenticated(BasePermission): """ def has_permission(self, request, view): - return request.user and request.user.is_authenticated + return bool(request.user and request.user.is_authenticated) class IsAdminUser(BasePermission): @@ -119,7 +119,7 @@ class IsAdminUser(BasePermission): """ def has_permission(self, request, view): - return request.user and request.user.is_staff + return bool(request.user and request.user.is_staff) class IsAuthenticatedOrReadOnly(BasePermission): @@ -128,7 +128,7 @@ class IsAuthenticatedOrReadOnly(BasePermission): """ def has_permission(self, request, view): - return ( + return bool( request.method in SAFE_METHODS or request.user and request.user.is_authenticated