Skip to content

Commit d158ef8

Browse files
committed
more targeted error message on out-of-order callback args
1 parent bda5823 commit d158ef8

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Diff for: dash/_validate.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88

99
def validate_callback(output, inputs, state, extra_args, types):
10+
is_multi = isinstance(output, (list, tuple))
11+
12+
outputs = output if is_multi else [output]
13+
1014
Input, Output, State = types
1115
if extra_args:
1216
if not isinstance(extra_args[0], (Output, Input, State)):
@@ -24,17 +28,16 @@ def validate_callback(output, inputs, state, extra_args, types):
2428
raise exceptions.IncorrectTypeException(
2529
"""
2630
In a callback definition, you must provide all Outputs first,
27-
"then all Inputs, then all States. Found this out of order:
31+
then all Inputs, then all States. After this item:
32+
{}
33+
we found this item next:
2834
{}
2935
""".format(
30-
repr(extra_args)
36+
repr((outputs + inputs + state)[-1]),
37+
repr(extra_args[0])
3138
)
3239
)
3340

34-
is_multi = isinstance(output, (list, tuple))
35-
36-
outputs = output if is_multi else [output]
37-
3841
for args in [outputs, inputs, state]:
3942
for arg in args:
4043
validate_callback_arg(arg)

Diff for: tests/integration/callbacks/test_validation.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,29 @@ def test_cbva001_callback_dep_types():
2424
]
2525
)
2626

27-
with pytest.raises(IncorrectTypeException):
27+
with pytest.raises(IncorrectTypeException) as err:
2828

2929
@app.callback([[Output("out1", "children")]], [Input("in1", "children")])
3030
def f(i):
3131
return i
3232

3333
pytest.fail("extra output nesting")
3434

35+
assert "must be `Output`, `Input`, or `State`" in err.value.args[0]
36+
assert "[<Output `out1.children`>]" in err.value.args[0]
37+
38+
with pytest.raises(IncorrectTypeException) as err:
39+
40+
@app.callback(Input("in1", "children"), Output("out1", "children"))
41+
def f2(i):
42+
return i
43+
44+
pytest.fail("out-of-order args")
45+
46+
assert "Outputs first,\nthen all Inputs, then all States." in err.value.args[0]
47+
assert "<Input `in1.children`>" in err.value.args[0]
48+
assert "<Output `out1.children`>" in err.value.args[0]
49+
3550
# all OK with tuples
3651
@app.callback(
3752
(Output("out1", "children"),),

0 commit comments

Comments
 (0)