Skip to content

Commit 358c508

Browse files
authored
Merge pull request #1640 from remibaar/bugfix/1624_handle_missing_timing_information_gracefully
[Bugfix] Handle missing `timing_information` gracefully
2 parents 26cec05 + 6d2cb4e commit 358c508

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## [UNRELEASED]
6+
### Fixed
7+
- [#1640](https://github.com/plotly/dash/pull/1640) Fix [#1475](https://github.com/plotly/dash/issues/1475), missing `timing_information` after certain modifications to Flask behavior
8+
59
## [1.20.0] - 2021-04-08
610

711
## Dash and Dash Renderer

dash/dash.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,10 +1468,15 @@ def _before_request():
14681468
}
14691469

14701470
def _after_request(response):
1471-
dash_total = flask.g.timing_information["__dash_server"]
1472-
dash_total["dur"] = round((time.time() - dash_total["dur"]) * 1000)
1471+
timing_information = flask.g.get("timing_information", None)
1472+
if timing_information is None:
1473+
return response
14731474

1474-
for name, info in flask.g.timing_information.items():
1475+
dash_total = timing_information.get("__dash_server", None)
1476+
if dash_total is not None:
1477+
dash_total["dur"] = round((time.time() - dash_total["dur"]) * 1000)
1478+
1479+
for name, info in timing_information.items():
14751480

14761481
value = name
14771482
if info.get("desc") is not None:

tests/integration/devtools/test_devtools_ui.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from time import sleep
2+
import flask
23

34
import dash_core_components as dcc
45
import dash_html_components as html
@@ -224,3 +225,38 @@ def set_b(a):
224225

225226
dash_duo.wait_for_text_to_equal("#b", "xyz")
226227
dash_duo.wait_for_no_elements("._dash-undo-redo")
228+
229+
230+
def test_dvui007_other_before_request_func(dash_thread_server, dash_br):
231+
# won't use `bash_br`, because it expects an dash app, but it gets an static html page.
232+
# we take only the selenium driver from `bash_br`, this driver has already been set-up.
233+
driver = dash_br.driver
234+
235+
app = dash.Dash(__name__)
236+
app.layout = html.Div(
237+
[html.P(id="just_an_id", children="You should never see this")]
238+
)
239+
240+
# create alternative response, for the endpoint '/'
241+
# servering an alternative response, will disable further `before_request` functions e.g. those by dash
242+
@app.server.before_request
243+
def create_an_alternative_response():
244+
if flask.request.endpoint == "/":
245+
return flask.Response(
246+
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
247+
"<title>Alternative repsonse</title>\n"
248+
'<h1 id="alternative_id">Alternative response header</h1>\n',
249+
200,
250+
mimetype="text/html",
251+
)
252+
253+
dash_thread_server.start(
254+
app,
255+
debug=True,
256+
use_reloader=False,
257+
use_debugger=True,
258+
dev_tools_hot_reload=False,
259+
)
260+
261+
driver.get(dash_thread_server.url)
262+
driver.find_element_by_id("alternative_id")

0 commit comments

Comments
 (0)