Skip to content

Commit 877aaa9

Browse files
committed
Fix werkzeug 2.1.0 import & dev tools error html rendering.
1 parent e87339f commit 877aaa9

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

dash/dash-renderer/src/components/error/FrontEnd/FrontEndError.react.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function UnconnectedErrorContent({error, base}) {
110110
)}
111111
{/* Backend Error */}
112112
{typeof error.html !== 'string' ? null : error.html.indexOf(
113-
'<!DOCTYPE HTML'
113+
'<!DOCTYPE'
114114
) === 0 ? (
115115
<div className='dash-be-error__st'>
116116
<div className='dash-backend-error'>

dash/dash.py

+33-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
import flask
1717
from flask_compress import Compress
18-
from werkzeug.debug.tbtools import get_current_traceback
18+
19+
from werkzeug.debug import tbtools
20+
from werkzeug.security import gen_salt
21+
1922
from pkg_resources import get_distribution, parse_version
2023
from dash import dcc
2124
from dash import html
@@ -102,6 +105,30 @@
102105
_re_renderer_scripts_id = 'id="_dash-renderer', "new DashRenderer"
103106

104107

108+
def _get_traceback(secret, error):
109+
def _get_skip(text):
110+
skip = 0
111+
for i, line in enumerate(text.splitlines()):
112+
if "%% callback invoked %%" in line:
113+
skip = int((i + 1) / 2)
114+
break
115+
return skip
116+
117+
# werkzeug<2.1.0
118+
if hasattr(tbtools, "get_current_traceback"):
119+
tb = tbtools.get_current_traceback()
120+
skip = _get_skip(tb.plaintext)
121+
return tbtools.get_current_traceback(skip=skip).render_full()
122+
123+
tb = tbtools.DebugTraceback(error) # pylint: disable=no-member
124+
skip = _get_skip(tb.render_traceback_text())
125+
126+
# pylint: disable=no-member
127+
return tbtools.DebugTraceback(error, skip=skip).render_debugger_html(
128+
True, secret, True
129+
)
130+
131+
105132
class _NoUpdate:
106133
# pylint: disable=too-few-public-methods
107134
pass
@@ -1756,19 +1783,16 @@ def enable_dev_tools(
17561783

17571784
if debug and dev_tools.prune_errors:
17581785

1786+
secret = gen_salt(20)
1787+
17591788
@self.server.errorhandler(Exception)
1760-
def _wrap_errors(_):
1789+
def _wrap_errors(error):
17611790
# find the callback invocation, if the error is from a callback
17621791
# and skip the traceback up to that point
17631792
# if the error didn't come from inside a callback, we won't
17641793
# skip anything.
1765-
tb = get_current_traceback()
1766-
skip = 0
1767-
for i, line in enumerate(tb.plaintext.splitlines()):
1768-
if "%% callback invoked %%" in line:
1769-
skip = int((i + 1) / 2)
1770-
break
1771-
return get_current_traceback(skip=skip).render_full(), 500
1794+
tb = _get_traceback(secret, error)
1795+
return tb, 500
17721796

17731797
if debug and dev_tools.ui:
17741798

0 commit comments

Comments
 (0)