diff options
| author | Armin Ronacher <armin.ronacher@active-4.com> | 2016-05-18 23:51:24 +0200 |
|---|---|---|
| committer | Armin Ronacher <armin.ronacher@active-4.com> | 2016-05-18 23:51:24 +0200 |
| commit | 8892bb12882a001f0ccb4f94df3c957da0a6ee61 (patch) | |
| tree | 151b45b18ca40eb49d2edad60723ef46961d422e | |
| parent | 520746d847682508e946811e8a05b2098079dadf (diff) | |
| download | raven-feature/safeguard-user.tar.gz | |
Handle user errors from django better.feature/safeguard-user
This fixes #771
| -rw-r--r-- | raven/contrib/django/client.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/raven/contrib/django/client.py b/raven/contrib/django/client.py index 00a555c..3f2bd41 100644 --- a/raven/contrib/django/client.py +++ b/raven/contrib/django/client.py @@ -142,19 +142,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 = {} |
