Duck-type check the user object instead of doing an instance check. This fixes #718
This commit is contained in:
parent
54192ad2df
commit
475d379f09
2
CHANGES
2
CHANGES
|
@ -3,6 +3,8 @@ Version 5.10.1
|
|||
|
||||
* Fixed a problem where bytes as keys in dictionaries caused problems
|
||||
on data sanitization if those bytes were outside of the ASCII range.
|
||||
* Django client no longer requires the user object to be a subclass
|
||||
of the base model.
|
||||
|
||||
Version 5.10.0
|
||||
--------------
|
||||
|
|
|
@ -34,7 +34,8 @@ class DjangoClient(Client):
|
|||
logger = logging.getLogger('sentry.errors.client.django')
|
||||
|
||||
def get_user_info(self, user):
|
||||
if not user.is_authenticated():
|
||||
if hasattr(user, 'is_authenticated') and \
|
||||
not user.is_authenticated():
|
||||
return {}
|
||||
|
||||
user_info = {
|
||||
|
@ -52,19 +53,11 @@ class DjangoClient(Client):
|
|||
return user_info
|
||||
|
||||
def get_data_from_request(self, request):
|
||||
try:
|
||||
from django.contrib.auth.models import AbstractBaseUser as BaseUser
|
||||
except ImportError:
|
||||
from django.contrib.auth.models import User as BaseUser # NOQA
|
||||
except RuntimeError:
|
||||
# If the contenttype / user applications are not installed trying to
|
||||
# import the user models will fail for django >= 1.9.
|
||||
BaseUser = None
|
||||
|
||||
result = {}
|
||||
|
||||
if BaseUser and hasattr(request, 'user') and isinstance(request.user, BaseUser):
|
||||
result['user'] = self.get_user_info(request.user)
|
||||
user = getattr(request, 'user', None)
|
||||
if user is not None:
|
||||
result['user'] = self.get_user_info(user)
|
||||
|
||||
try:
|
||||
uri = request.build_absolute_uri()
|
||||
|
|
Loading…
Reference in New Issue