Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Handle missing timing_information gracefully #1640

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,10 +1468,16 @@ 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():
timing_information_dash = timing_information.get("__dash_server", None)
if timing_information_dash is not None:
dash_total = timing_information["__dash_server"]
remibaar marked this conversation as resolved.
Show resolved Hide resolved
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")