Declaring callbacks with some non-existing Inputs results in a JS error

I figured out how to solve this, but figured I’d post about it because the initial symptom was this inscrutable error in the console:
Uncaught TypeError: undefined does not have a method named "concat"(…)

I have an app with tabs and buttons. Some buttons appear on one tab, some buttons appear on the other. I’d set up a callback function to be able to use a dynamic number of buttons like:

@app.callback(Output(OUTPUTDIV, 'children'),
              [Input(button_id, 'n_clicks') for button_id in BUTTONS])
def button_clicks(*args):
     for n_clicks in args:
          #do something

It worked fine with one tab, but when I added a second tab, and a second set of buttons, the app broke. No errors were showing up in Python, but the buttons wouldn’t do anything when clicked anymore. Eventually I found the inscrutable error above, but was puzzled, since the Python code would be able to handle if arguments passed to it were None so it took me a while to figure out what was happening.

My solution will be to iterate over the tabs and create a button_clicks() function for each. Maybe this will be a problem for other setups?

I don’t really know what’s happening on the Javascript side, but it would be nice if JS would pass back None values to the callback :slight_smile:

Have you ever gotten that feeling where you search for an issue and find your own post?

This happened again because we’re missing data from a sensor, and the app was still creating an object for that sensor for the most recent period for which we had data. But if the user changes to select their own timeperiod, this sensor object disappears and the callback associated with it breaks a bunch of the app.

I noticed this by having DEBUG logging statements in different callbacks and comparing which ones fire in a good scenario vs. a breaking one.

I got the same error, and figured (in my case) what what the cause of it.
I had a multi-page app, and so disabled the callbacks exceptions with
app.config.suppress_callback_exceptions = True

This error arose when I had callbacks with Inputs and Outputs assigned to missing elements (some typos in my case).

This is likely to be the major cause of this problem. Too bad the debugging information is so scarce.

In my case, what happened was that I was trying to reference missing inputs which was due to some oversight in my code… fixing that solved the issue for me

@rad can you try to share some of your working code related to this issue? I.e. how you setup your tabs with input/output…

1 Like

Super sorry, haven’t been working in Dash for a while so I haven’t been using the forums as much.

Here’s the commit where I fixed an element of this. I’ve kind of forgotten what I did but if you’re still interested and have any questions after skimming the code, I can take a deeper look.