Skip to content

Commit e452952

Browse files
committed
Django 2.0 compatibility: User.is_authenticated is now a property.
Fixes #397
1 parent 702c7da commit e452952

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ddtrace/contrib/django/compat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import django
2+
3+
4+
if django.VERSION >= (2,):
5+
def user_is_authenticated(user):
6+
return user.is_authenticated
7+
else:
8+
def user_is_authenticated(user):
9+
return user.is_authenticated()

ddtrace/contrib/django/middleware.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# project
44
from .conf import settings
5+
from .compat import user_is_authenticated
56

67
from ...ext import http
78
from ...contrib import func_name
@@ -134,7 +135,7 @@ def _set_auth_tags(span, request):
134135
return span
135136

136137
if hasattr(user, 'is_authenticated'):
137-
span.set_tag('django.user.is_authenticated', user.is_authenticated())
138+
span.set_tag('django.user.is_authenticated', user_is_authenticated(user))
138139

139140
uid = getattr(user, 'pk', None)
140141
if uid:

0 commit comments

Comments
 (0)