A nonexistent object was used in an `Output` of a Dash callback, but it exists

I’m not posting a MWE because it is too complicated to extract it from the original app for now, but the following example should be enough to understand the issue.

I have 3 different callbacks targeting the same Output components, so I use allow_duplicate and prevent_initial_call

# First Callback
@callback(
    [Output("locations", "options"),
     Output("locations", "value"),
      .....],
    Input("search-button", "n_clicks"),
)
def get_closest_address(n_clicks):
    logging.info("Called get_closest_address")

# Second callback
@callback(
    [Output("map-scatter-layer", "children", allow_duplicate=True),
     Output("locations", "options", allow_duplicate=True),
     Output("locations", "value", allow_duplicate=True),
     ....],
    Input("map", "clickData"),
    prevent_initial_call=True
)
def map_click(clickData):
    logging.info("Called map_click")

# Third callback
@callback(
    [Output("locations", "options", allow_duplicate=True),
     Output("locations", "value", allow_duplicate=True), ...],
    Input("geolocation", "local_date"),
    prevent_initial_call=True
)
def update_location_with_geolocate(_):
    logging.info("Called update_location_with_geolocate")

I get the error : ReferenceError: A nonexistent object was used in an Output of a Dash callback. The id of this object is locations and the property is options@65301cc199c777e9a149e81bbce741f2. The application seems to work just fine, though.

If I comment the third callback (update_location_with_geolocate function) I don’t get any error. The logging calls show that neither map_click nor update_location_with_geolocate are called when the application is loaded (as expected).
I’m trying to wrap my head around why, when update_location_with_geolocate is defined then there is no locations component defined in the layout, but there is when map_click is defined.

Ok, I think I solved it.

For some reason having the Geolocation component declared directly in the app layout was causing the callback associated with update_location_with_geodata to be triggered too early when the locations component was not yet in the layout (don’t ask me why).

I moved the Geolocation component in the specific Card where it should be used and now everything seems to work fine.

In theory, it shouldn’t matter where it is placed, because it doesn’t appear in the layout, however I guess its position would affect when the location is requested from the browser, thus updating either the date or position returned by it.

1 Like