فهرست منبع

HUE-8737 [core] Avoid double 500 on traceback with py3

TypeError: Object of type 'FrameSummary' is not JSON serializable
Romain 6 سال پیش
والد
کامیت
e4727ec78b
2فایلهای تغییر یافته به همراه15 افزوده شده و 8 حذف شده
  1. 12 8
      desktop/core/src/desktop/lib/django_util.py
  2. 3 0
      desktop/core/src/desktop/lib/exceptions_renderable.py

+ 12 - 8
desktop/core/src/desktop/lib/django_util.py

@@ -228,12 +228,14 @@ def render(template, request, data, json=None, template_lib=None, force_template
       return render_json(data, request.GET.get("callback"), status=status)
   else:
     data.update({'user': request.user})
-    return _render_to_response(template,
-                               request,
-                               RequestContext(request, data),
-                               template_lib=template_lib,
-                               status=status,
-                               **kwargs)
+    return _render_to_response(
+        template,
+        request,
+        RequestContext(request, data),
+        template_lib=template_lib,
+        status=status,
+        **kwargs
+    )
 
 
 def render_injected(http_resp, extra_html):
@@ -291,21 +293,23 @@ class IllegalJsonpCallbackNameException(Exception):
 
 def render_json(data, jsonp_callback=None, js_safe=False, status=200):
   """
-  Renders data as json.  If jsonp is specified, wraps
-  the result in a function.
+  Renders data as json.  If jsonp is specified, wraps the result in a function.
   """
   if settings.DEBUG:
     indent = 2
   else:
     indent = 0
+
   if js_safe:
     json = encode_json_for_js(data, indent)
   else:
     json = encode_json(data, indent)
+
   if jsonp_callback is not None:
     if not VALID_JSON_IDENTIFIER.match(jsonp_callback):
       raise IllegalJsonpCallbackNameException("Invalid jsonp callback name: %s" % jsonp_callback)
     json = "%s(%s);" % (jsonp_callback, json)
+
   return HttpResponse(json, content_type='text/javascript', status=status)
 
 def update_if_dirty(model_instance, **kwargs):

+ 3 - 0
desktop/core/src/desktop/lib/exceptions_renderable.py

@@ -73,6 +73,9 @@ class PopupException(Exception):
 
     if not request.ajax:
       data['request'] = request
+    else:
+      data['traceback'] = traceback.format_list(data['traceback'])
+
     response = desktop.lib.django_util.render("popup_error.mako", request, data)
     if self.error_code == 500 and data['is_embeddable']: # Hue 4
       response.status_code = 200