mirror of
https://github.com/django/django.git
synced 2025-06-16 00:49:12 +00:00
fix: add a threshold limit for variable size in pretty printing exception report
This commit is contained in:
parent
0630ca5725
commit
9c1458d9ee
@ -2,6 +2,7 @@ import functools
|
|||||||
import inspect
|
import inspect
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
|
import reprlib
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
import warnings
|
import warnings
|
||||||
@ -310,6 +311,9 @@ class SafeExceptionReporterFilter:
|
|||||||
class ExceptionReporter:
|
class ExceptionReporter:
|
||||||
"""Organize and coordinate reporting on exceptions."""
|
"""Organize and coordinate reporting on exceptions."""
|
||||||
|
|
||||||
|
repr_instance = reprlib.Repr(maxstring=4096, maxlist=1000)
|
||||||
|
MAX_VAR_SIZE_PRETTY_PRINT = 512 * 1024 # 512KB
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def html_template_path(self):
|
def html_template_path(self):
|
||||||
return builtin_template_path("technical_500.html")
|
return builtin_template_path("technical_500.html")
|
||||||
@ -348,10 +352,14 @@ class ExceptionReporter:
|
|||||||
self.postmortem = self.exc_value.chain or [self.exc_value]
|
self.postmortem = self.exc_value.chain or [self.exc_value]
|
||||||
|
|
||||||
frames = self.get_traceback_frames()
|
frames = self.get_traceback_frames()
|
||||||
|
|
||||||
for i, frame in enumerate(frames):
|
for i, frame in enumerate(frames):
|
||||||
if "vars" in frame:
|
if "vars" in frame:
|
||||||
frame_vars = []
|
frame_vars = []
|
||||||
for k, v in frame["vars"]:
|
for k, v in frame["vars"]:
|
||||||
|
if sys.getsizeof(v) > self.MAX_VAR_SIZE_PRETTY_PRINT:
|
||||||
|
v = self.repr_instance.repr(v)
|
||||||
|
else:
|
||||||
v = pprint(v)
|
v = pprint(v)
|
||||||
# Trim large blobs of data
|
# Trim large blobs of data
|
||||||
if len(v) > 4096:
|
if len(v) > 4096:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user