diff options
| author | Andreas Pelme <andreas@pelme.se> | 2016-12-03 19:51:32 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-06 12:28:00 -0500 |
| commit | 373140b07aa452946ccb6d5b0317fa09ed5bbdc2 (patch) | |
| tree | 6c2a38b6306357fa36a040c9eeb3b40967e5e199 /django | |
| parent | 8f76673f344750d863ae0856040d89c9f67baa8c (diff) | |
Fixed #27567 -- Fixed crash in the debug view when request.user errors.
Diffstat (limited to 'django')
| -rw-r--r-- | django/views/debug.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/django/views/debug.py b/django/views/debug.py index fff67249c6..a32362b31c 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -285,11 +285,23 @@ class ExceptionReporter(object): 'ascii', errors='replace' ) from django import get_version + + if self.request is None: + user_str = None + else: + try: + user_str = force_text(self.request.user) + except Exception: + # request.user may raise OperationalError if the database is + # unavailable, for example. + user_str = '[unable to retrieve the current user]' + c = { 'is_email': self.is_email, 'unicode_hint': unicode_hint, 'frames': frames, 'request': self.request, + 'user_str': user_str, 'filtered_POST_items': self.filter.get_post_parameters(self.request).items(), 'settings': get_safe_settings(), 'sys_executable': sys.executable, @@ -903,9 +915,9 @@ Exception Value: {{ exception_value|force_escape }} <h2>Request information</h2> {% if request %} - {% if request.user %} + {% if user_str %} <h3 id="user-info">USER</h3> - <p>{{ request.user }}</p> + <p>{{ user_str }}</p> {% endif %} <h3 id="get-info">GET</h3> @@ -1104,7 +1116,7 @@ File "{{ frame.filename }}" in {{ frame.function }} {% if exception_type %}Exception Type: {{ exception_type }}{% if request %} at {{ request.path_info }}{% endif %} {% if exception_value %}Exception Value: {{ exception_value }}{% endif %}{% endif %}{% endif %} {% if request %}Request information: -{% if request.user %}USER: {{ request.user }}{% endif %} +{% if user_str %}USER: {{ user_str }}{% endif %} GET:{% for k, v in request_GET_items %} {{ k }} = {{ v|stringformat:"r" }}{% empty %} No GET data{% endfor %} |
