Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit e52c837

Browse files
authored
fix(django): Avoid deprecation warnings when calling is_authenticated (#1112)
1 parent 7f3e1b5 commit e52c837

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

raven/contrib/django/client.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import time
1313
import logging
1414

15+
from django import VERSION as DJANGO_VERSION
1516
from django.conf import settings
1617
from django.core.exceptions import SuspiciousOperation
1718
from django.http import HttpRequest
@@ -37,6 +38,14 @@
3738
__all__ = ('DjangoClient',)
3839

3940

41+
if DJANGO_VERSION < (1, 10):
42+
def is_authenticated(request_user):
43+
return request_user.is_authenticated()
44+
else:
45+
def is_authenticated(request_user):
46+
return request_user.is_authenticated
47+
48+
4049
class _FormatConverter(object):
4150

4251
def __init__(self, param_mapping):
@@ -152,15 +161,9 @@ def get_user_info(self, request):
152161
return user_info
153162

154163
try:
155-
if hasattr(user, 'is_authenticated'):
156-
# is_authenticated was a method in Django < 1.10
157-
if callable(user.is_authenticated):
158-
authenticated = user.is_authenticated()
159-
else:
160-
authenticated = user.is_authenticated
161-
if not authenticated:
162-
return user_info
163-
164+
authenticated = is_authenticated(user)
165+
if not authenticated:
166+
return user_info
164167
user_info['id'] = user.pk
165168

166169
if hasattr(user, 'email'):

0 commit comments

Comments
 (0)