Skip to content

Commit d6d4001

Browse files
authored
Merge pull request #165 from cserteGT3/cst-i163
Throw error on multiple callbacks targeting same output
2 parents 0a9e25f + 1bf4166 commit d6d4001

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/app/callbacks.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ function _callback!(func::Union{Function, ClientsideFunction, String}, app::Dash
129129
check_callback(func, app, deps)
130130

131131
out_symbol = Symbol(output_string(deps))
132+
haskey(app.callbacks, out_symbol) && error("Multiple callbacks can not target the same output. Offending output: $(out_symbol)")
132133
callback_func = make_callback_func!(app, func, deps)
133134
push!(
134135
app.callbacks,

test/callbacks.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ end
306306

307307
end
308308

309+
@testset "multiple callbacks targeting same output" begin
310+
app = dash()
311+
312+
app.layout = html_div() do
313+
dcc_input(id = "my-id", value="initial value", type = "text"),
314+
dcc_input(id = "my-id2", value="initial value2", type = "text"),
315+
html_div(id = "my-div")
316+
end
317+
318+
callback!(app, Output("my-div","children"), Input("my-id","value")) do value
319+
return value
320+
end
321+
322+
testresult = @test_throws ErrorException callback!(app, Output("my-div","children"), Input("my-id2","value")) do value
323+
return "v_$(value)"
324+
end
325+
@test testresult.value.msg == "Multiple callbacks can not target the same output. Offending output: my-div.children"
326+
end
327+
309328
@testset "empty triggered params" begin
310329
app = dash()
311330
app.layout = html_div() do

0 commit comments

Comments
 (0)