MCPcopy
hub / github.com/plotly/dash / add_context

Function add_context

dash/_callback.py:736–805  ·  view source on GitHub ↗

Handles synchronous callbacks with context management.

(*args, **kwargs)

Source from the content-addressed store, hash-verified

734
735 @wraps(func)
736 def add_context(*args, **kwargs):
737 """Handles synchronous callbacks with context management."""
738 error_handler = on_error or kwargs.pop("app_on_error", None)
739
740 (
741 output_spec,
742 callback_ctx,
743 func_args,
744 func_kwargs,
745 app,
746 original_packages,
747 has_update,
748 ) = _initialize_context(
749 args, kwargs, inputs_state_indices, has_output, insert_output
750 )
751
752 response: CallbackExecutionResponse = {"multi": True}
753 jsonResponse: Optional[str] = None
754 try:
755 if background is not None:
756 adapter = get_app().backend.request_adapter()
757 if not (adapter and adapter.args.get("cacheKey")):
758 return _setup_background_callback(
759 kwargs,
760 background,
761 background_key,
762 func,
763 func_args,
764 func_kwargs,
765 callback_ctx,
766 )
767
768 output_value, has_update, skip = _update_background_callback(
769 error_handler, callback_ctx, response, kwargs, background, multi
770 )
771 if skip:
772 return output_value
773 else:
774 output_value = _invoke_callback(func, *func_args, **func_kwargs) # type: ignore[reportArgumentType]
775 except PreventUpdate:
776 raise
777 except Exception as err: # pylint: disable=broad-exception-caught
778 if error_handler:
779 output_value = error_handler(err)
780 if output_value is None and output_spec:
781 output_value = NoUpdate()
782 else:
783 raise err
784
785 _prepare_response(
786 output_value,
787 output_spec,
788 multi,
789 response,
790 callback_ctx,
791 app,
792 original_packages,
793 background,

Callers

nothing calls this directly

Calls 10

get_appFunction · 0.90
_initialize_contextFunction · 0.85
_invoke_callbackFunction · 0.85
NoUpdateClass · 0.85
_prepare_responseFunction · 0.85
to_jsonFunction · 0.85
popMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…