summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2016-08-04 11:31:49 -0700
committerGitHub <noreply@github.com>2016-08-04 11:31:49 -0700
commitde78c06eaade45f21ed84e10b43ae677ba369966 (patch)
tree5bfa203b92277eaf3589b2115f9ecfcf3b107500
parent8dd26a7c813f9d57c9cfcf916ea9c142edce130e (diff)
parent8892bb12882a001f0ccb4f94df3c957da0a6ee61 (diff)
downloadraven-de78c06eaade45f21ed84e10b43ae677ba369966.tar.gz
Merge pull request #772 from getsentry/feature/safeguard-user
Handle user errors from django better.
-rw-r--r--raven/contrib/django/client.py32
1 files changed, 19 insertions, 13 deletions
diff --git a/raven/contrib/django/client.py b/raven/contrib/django/client.py
index ad2f6e4..b497c1b 100644
--- a/raven/contrib/django/client.py
+++ b/raven/contrib/django/client.py
@@ -144,19 +144,25 @@ class DjangoClient(Client):
not user.is_authenticated():
return None
- user_info = {
- 'id': user.pk,
- }
-
- if hasattr(user, 'email'):
- user_info['email'] = user.email
-
- if hasattr(user, 'get_username'):
- user_info['username'] = user.get_username()
- elif hasattr(user, 'username'):
- user_info['username'] = user.username
-
- return user_info
+ user_info = {}
+ try:
+ user_info['id'] = user.pk
+
+ if hasattr(user, 'email'):
+ user_info['email'] = user.email
+
+ if hasattr(user, 'get_username'):
+ user_info['username'] = user.get_username()
+ elif hasattr(user, 'username'):
+ user_info['username'] = user.username
+ except Exception:
+ # We expect that user objects can be somewhat broken at times
+ # and try to just handle as much as possible and ignore errors
+ # as good as possible here.
+ pass
+
+ if user_info:
+ return user_info
def get_data_from_request(self, request):
result = {}