-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix #1383 prevent_initial_call positional arg regression #1384
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c3dd40a
fix prevent_initial_call as positional arg to callback
alexcjohnson ea4bf5c
test that tuples work for callback args
alexcjohnson e6b5559
changelog for prevent_initial_call fix, and black
alexcjohnson 708f36e
downgrade cryptography, try to fix windows build
alexcjohnson 45ef078
Merge branch 'dev' into 1383-callback-args-fix
alexcjohnson 2669aa9
modernize flaky request hooks test
alexcjohnson 3ba5af7
Merge branch '1383-callback-args-fix' of github.com:plotly/dash into …
alexcjohnson 5a702bf
black
alexcjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -193,3 +193,33 @@ def o2(i, s): | |||
dash_duo.start_server(app) | ||||
dash_duo.wait_for_text_to_equal("#out1", "1: High") | ||||
dash_duo.wait_for_text_to_equal("#out2", "2: High") | ||||
|
||||
|
||||
def test_cbva005_tuple_args(dash_duo): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL - I thought this was going to be broken: Line 165 in fed4a91
but turns out even though Anyway now it's tested :) |
||||
app = Dash(__name__) | ||||
app.layout = html.Div( | ||||
[ | ||||
html.Div("Yo", id="in1"), | ||||
html.Div("lo", id="in2"), | ||||
html.Div(id="out1"), | ||||
html.Div(id="out2"), | ||||
] | ||||
) | ||||
|
||||
@app.callback( | ||||
Output("out1", "children"), (Input("in1", "children"), Input("in2", "children")) | ||||
) | ||||
def f(i1, i2): | ||||
return "1: " + i1 + i2 | ||||
|
||||
@app.callback( | ||||
(Output("out2", "children"),), | ||||
Input("in1", "children"), | ||||
(State("in2", "children"),), | ||||
) | ||||
def g(i1, i2): | ||||
return ("2: " + i1 + i2,) | ||||
|
||||
dash_duo.start_server(app) | ||||
dash_duo.wait_for_text_to_equal("#out1", "1: Yolo") | ||||
dash_duo.wait_for_text_to_equal("#out2", "2: Yolo") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import json | ||
|
||
import dash_html_components as html | ||
import dash_core_components as dcc | ||
from dash import Dash | ||
from dash.dependencies import Output, Input | ||
|
||
|
||
def test_rdrh001_request_hooks(dash_duo): | ||
app = Dash(__name__) | ||
|
||
app.index_string = """<!DOCTYPE html> | ||
<html> | ||
<head> | ||
{%metas%} | ||
<title>{%title%}</title> | ||
{%favicon%} | ||
{%css%} | ||
</head> | ||
<body> | ||
<div>Testing custom DashRenderer</div> | ||
{%app_entry%} | ||
<footer> | ||
{%config%} | ||
{%scripts%} | ||
<script id="_dash-renderer" type"application/json"> | ||
const renderer = new DashRenderer({ | ||
request_pre: (payload) => { | ||
var output = document.getElementById('output-pre') | ||
var outputPayload = document.getElementById('output-pre-payload') | ||
if(output) { | ||
output.innerHTML = 'request_pre changed this text!'; | ||
} | ||
if(outputPayload) { | ||
outputPayload.innerHTML = JSON.stringify(payload); | ||
} | ||
}, | ||
request_post: (payload, response) => { | ||
var output = document.getElementById('output-post') | ||
var outputPayload = document.getElementById('output-post-payload') | ||
var outputResponse = document.getElementById('output-post-response') | ||
if(output) { | ||
output.innerHTML = 'request_post changed this text!'; | ||
} | ||
if(outputPayload) { | ||
outputPayload.innerHTML = JSON.stringify(payload); | ||
} | ||
if(outputResponse) { | ||
outputResponse.innerHTML = JSON.stringify(response); | ||
} | ||
} | ||
}) | ||
</script> | ||
</footer> | ||
<div>With request hooks</div> | ||
</body> | ||
</html>""" | ||
|
||
app.layout = html.Div( | ||
[ | ||
dcc.Input(id="input", value="initial value"), | ||
html.Div( | ||
html.Div( | ||
[ | ||
html.Div(id="output-1"), | ||
html.Div(id="output-pre"), | ||
html.Div(id="output-pre-payload"), | ||
html.Div(id="output-post"), | ||
html.Div(id="output-post-payload"), | ||
html.Div(id="output-post-response"), | ||
] | ||
) | ||
), | ||
] | ||
) | ||
|
||
@app.callback(Output("output-1", "children"), [Input("input", "value")]) | ||
def update_output(value): | ||
return value | ||
|
||
dash_duo.start_server(app) | ||
|
||
_in = dash_duo.find_element("#input") | ||
dash_duo.clear_input(_in) | ||
|
||
_in.send_keys("fire request hooks") | ||
|
||
dash_duo.wait_for_text_to_equal("#output-1", "fire request hooks") | ||
dash_duo.wait_for_text_to_equal("#output-pre", "request_pre changed this text!") | ||
dash_duo.wait_for_text_to_equal("#output-post", "request_post changed this text!") | ||
|
||
assert json.loads(dash_duo.find_element("#output-pre-payload").text) == { | ||
"output": "output-1.children", | ||
"outputs": {"id": "output-1", "property": "children"}, | ||
"changedPropIds": ["input.value"], | ||
"inputs": [{"id": "input", "property": "value", "value": "fire request hooks"}], | ||
} | ||
|
||
assert json.loads(dash_duo.find_element("#output-post-payload").text) == { | ||
"output": "output-1.children", | ||
"outputs": {"id": "output-1", "property": "children"}, | ||
"changedPropIds": ["input.value"], | ||
"inputs": [{"id": "input", "property": "value", "value": "fire request hooks"}], | ||
} | ||
|
||
assert json.loads(dash_duo.find_element("#output-post-response").text) == { | ||
"output-1": {"children": "fire request hooks"} | ||
} | ||
|
||
dash_duo.percy_snapshot(name="request-hooks render") | ||
|
||
|
||
def test_rdrh002_with_custom_renderer_interpolated(dash_duo): | ||
|
||
renderer = """ | ||
<script id="_dash-renderer" type="application/javascript"> | ||
console.log('firing up a custom renderer!') | ||
const renderer = new DashRenderer({ | ||
request_pre: () => { | ||
var output = document.getElementById('output-pre') | ||
if(output) { | ||
output.innerHTML = 'request_pre was here!'; | ||
} | ||
}, | ||
request_post: () => { | ||
var output = document.getElementById('output-post') | ||
if(output) { | ||
output.innerHTML = 'request_post!!!'; | ||
} | ||
} | ||
}) | ||
</script> | ||
""" | ||
|
||
class CustomDash(Dash): | ||
def interpolate_index(self, **kwargs): | ||
return """<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>My App</title> | ||
</head> | ||
<body> | ||
|
||
<div id="custom-header">My custom header</div> | ||
{app_entry} | ||
{config} | ||
{scripts} | ||
{renderer} | ||
<div id="custom-footer">My custom footer</div> | ||
</body> | ||
</html>""".format( | ||
app_entry=kwargs["app_entry"], | ||
config=kwargs["config"], | ||
scripts=kwargs["scripts"], | ||
renderer=renderer, | ||
) | ||
|
||
app = CustomDash() | ||
|
||
app.layout = html.Div( | ||
[ | ||
dcc.Input(id="input", value="initial value"), | ||
html.Div( | ||
html.Div( | ||
[ | ||
html.Div(id="output-1"), | ||
html.Div(id="output-pre"), | ||
html.Div(id="output-post"), | ||
] | ||
) | ||
), | ||
] | ||
) | ||
|
||
@app.callback(Output("output-1", "children"), [Input("input", "value")]) | ||
def update_output(value): | ||
return value | ||
|
||
dash_duo.start_server(app) | ||
|
||
input1 = dash_duo.find_element("#input") | ||
dash_duo.clear_input(input1) | ||
|
||
input1.send_keys("fire request hooks") | ||
|
||
dash_duo.wait_for_text_to_equal("#output-1", "fire request hooks") | ||
assert dash_duo.find_element("#output-pre").text == "request_pre was here!" | ||
assert dash_duo.find_element("#output-post").text == "request_post!!!" | ||
|
||
dash_duo.percy_snapshot(name="request-hooks interpolated") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to fix https://app.circleci.com/pipelines/github/plotly/dash/1693/workflows/002acae1-f322-4389-928c-f2c14deaab1b/jobs/27184
Seems like there's something weird going on in the latest release (tonight!) of
cryptography
, which is pulled in byrequests
- see eg pyca/cryptography#5412