Skip to content

Commit

Permalink
Merge pull request #1640 from remibaar/bugfix/1624_handle_missing_tim…
Browse files Browse the repository at this point in the history
…ing_information_gracefully

[Bugfix] Handle missing `timing_information` gracefully
  • Loading branch information
alexcjohnson authored May 17, 2021
2 parents 26cec05 + 6d2cb4e commit 358c508
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]
### Fixed
- [#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

## [1.20.0] - 2021-04-08

## Dash and Dash Renderer
Expand Down
11 changes: 8 additions & 3 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,10 +1468,15 @@ def _before_request():
}

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

for name, info in flask.g.timing_information.items():
dash_total = timing_information.get("__dash_server", None)
if dash_total is not None:
dash_total["dur"] = round((time.time() - dash_total["dur"]) * 1000)

for name, info in timing_information.items():

value = name
if info.get("desc") is not None:
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/devtools/test_devtools_ui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from time import sleep
import flask

import dash_core_components as dcc
import dash_html_components as html
Expand Down Expand Up @@ -224,3 +225,38 @@ def set_b(a):

dash_duo.wait_for_text_to_equal("#b", "xyz")
dash_duo.wait_for_no_elements("._dash-undo-redo")


def test_dvui007_other_before_request_func(dash_thread_server, dash_br):
# won't use `bash_br`, because it expects an dash app, but it gets an static html page.
# we take only the selenium driver from `bash_br`, this driver has already been set-up.
driver = dash_br.driver

app = dash.Dash(__name__)
app.layout = html.Div(
[html.P(id="just_an_id", children="You should never see this")]
)

# create alternative response, for the endpoint '/'
# servering an alternative response, will disable further `before_request` functions e.g. those by dash
@app.server.before_request
def create_an_alternative_response():
if flask.request.endpoint == "/":
return flask.Response(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n'
"<title>Alternative repsonse</title>\n"
'<h1 id="alternative_id">Alternative response header</h1>\n',
200,
mimetype="text/html",
)

dash_thread_server.start(
app,
debug=True,
use_reloader=False,
use_debugger=True,
dev_tools_hot_reload=False,
)

driver.get(dash_thread_server.url)
driver.find_element_by_id("alternative_id")

0 comments on commit 358c508

Please sign in to comment.