Errors from None inputs with chained callbacks


I’m developing an app which chains together several elements to dynamically filter through songs from a collection of music. The general flow looks like this.

  1. Spotify URI elements are parsed from the page URL, and the playlist/library is retrieved via the Spotify API, then stored in a hidden div.
    2.1) Slider bars for various stats are configured based on the min and max values in the data set.
    2.2) User tags are retrieved from the database for the songs in the collection and stored in another hidden div.
  2. A Dash table takes 1) the song data stored in the hidden div, 2.1) the values of the slider bars, and 2.2) the user tags stored in the other hidden div, and filters the collection by the ranges of the sliders, adds the song tags as a new column, and displays the filtered, tagged collection.
  3. A separate histogram for each stat updates based on 3) the filtered dataset.

My problem is that at every layer >2, a callback is fired for the element before the lower level elements are finished loading. The inputs on this initial callback is thus often None, and these None values cause Type Errors in the downstream code. This isn’t a problem on the client side - everything seems to work as normal - but it’s a huge pain for my server logs. I’ve got upwards of 40 downstream elements that error at least once every time a new playlist is viewed. This not only spams my logs in production, but also makes tracing more problematic errors a needle & haystack operation.

Is there some null value that I could have my callback functions return so that I can detect when a necessary input is None and emit this null value? Or is there some way I can silence/ignore specific types of Exceptions so that I can just raise this CallbackChain exception instead of a TypeError etc?



In a lot of callback functions I just add something like:

from dash.exceptions import PreventUpdate


def this_function(var, ... ):
    if var==None:
        raise PreventUpdate

    # other code

It’s not perfect, but it works for my stuff. Is this helpful? If not, some more detail and/or code would be useful to understand just how those Nones are generated and how they affect your app’s flow.

1 Like

Check this out. 📣 Dash 0.41.0 released Specifically the section on Partial Multi-Output - the noupdate feature might work better than passing back None depending on your app implementation.

1 Like