MCPcopy Index your code
hub / github.com/plotly/dash / _handle_rest_background_callback

Function _handle_rest_background_callback

dash/_callback.py:522–577  ·  view source on GitHub ↗
(
    output_value,
    callback_manager,
    response,
    error_handler,
    callback_ctx,
    multi,
    has_update=False,
    cache_key=None,
    job_id=None,
)

Source from the content-addressed store, hash-verified

520
521
522def _handle_rest_background_callback(
523 output_value,
524 callback_manager,
525 response,
526 error_handler,
527 callback_ctx,
528 multi,
529 has_update=False,
530 cache_key=None,
531 job_id=None,
532):
533 if cache_key is None or job_id is None:
534 adapter = get_app().backend.request_adapter()
535 cache_key = cache_key or (adapter.args.get("cacheKey") if adapter else None)
536 job_id = job_id or (adapter.args.get("job") if adapter else None)
537 # Must get job_running after get_result since get_results terminates it.
538 job_running = callback_manager.job_running(job_id)
539 if not job_running and output_value is callback_manager.UNDEFINED:
540 # Job canceled -> no output to close the loop.
541 output_value = NoUpdate()
542
543 elif isinstance(output_value, dict) and "background_callback_error" in output_value:
544 error = output_value.get("background_callback_error", {})
545 exc = BackgroundCallbackError(
546 f"An error occurred inside a background callback: {error['msg']}\n{error['tb']}"
547 )
548 if error_handler:
549 output_value = error_handler(exc)
550
551 if output_value is None:
552 output_value = NoUpdate()
553 # set_props from the error handler uses the original ctx
554 # instead of manager.get_updated_props since it runs in the
555 # request process.
556 has_update = (
557 _set_side_update(callback_ctx, response) or output_value is not None
558 )
559 else:
560 raise exc
561
562 if job_running and output_value is not callback_manager.UNDEFINED:
563 # cached results.
564 callback_manager.terminate_job(job_id)
565
566 if multi and isinstance(output_value, (list, tuple)):
567 output_value = [
568 NoUpdate() if NoUpdate.is_no_update(r) else r for r in output_value
569 ]
570 updated_props = callback_manager.get_updated_props(cache_key)
571 if len(updated_props) > 0:
572 response["sideUpdate"] = updated_props
573 has_update = True
574
575 if output_value is callback_manager.UNDEFINED:
576 return to_json(response), has_update, True
577 return output_value, has_update, False
578
579

Callers 1

Calls 10

get_appFunction · 0.90
NoUpdateClass · 0.85
_set_side_updateFunction · 0.85
to_jsonFunction · 0.85
is_no_updateMethod · 0.80
getMethod · 0.45
job_runningMethod · 0.45
terminate_jobMethod · 0.45
get_updated_propsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…