|
10 | 10 | handle_grouped_callback_args,
|
11 | 11 | Output,
|
12 | 12 | )
|
| 13 | +from .development.base_component import ComponentRegistry |
13 | 14 | from .exceptions import (
|
14 | 15 | InvalidCallbackReturnValue,
|
15 | 16 | PreventUpdate,
|
16 | 17 | WildcardInLongCallback,
|
17 | 18 | MissingLongCallbackManagerError,
|
18 | 19 | LongCallbackError,
|
| 20 | + ImportedInsideCallbackError, |
19 | 21 | )
|
20 | 22 |
|
21 | 23 | from ._grouping import (
|
@@ -354,11 +356,14 @@ def wrap_func(func):
|
354 | 356 | def add_context(*args, **kwargs):
|
355 | 357 | output_spec = kwargs.pop("outputs_list")
|
356 | 358 | app_callback_manager = kwargs.pop("long_callback_manager", None)
|
| 359 | + |
357 | 360 | callback_ctx = kwargs.pop(
|
358 | 361 | "callback_context", AttributeDict({"updated_props": {}})
|
359 | 362 | )
|
| 363 | + app = kwargs.pop("app", None) |
360 | 364 | callback_manager = long and long.get("manager", app_callback_manager)
|
361 | 365 | error_handler = on_error or kwargs.pop("app_on_error", None)
|
| 366 | + original_packages = set(ComponentRegistry.registry) |
362 | 367 |
|
363 | 368 | if has_output:
|
364 | 369 | _validate.validate_output_spec(insert_output, output_spec, Output)
|
@@ -557,6 +562,18 @@ def add_context(*args, **kwargs):
|
557 | 562 |
|
558 | 563 | response["response"] = component_ids
|
559 | 564 |
|
| 565 | + if len(ComponentRegistry.registry) != len(original_packages): |
| 566 | + diff_packages = list( |
| 567 | + set(ComponentRegistry.registry).difference(original_packages) |
| 568 | + ) |
| 569 | + if not allow_dynamic_callbacks: |
| 570 | + raise ImportedInsideCallbackError( |
| 571 | + f"Component librar{'y' if len(diff_packages) == 1 else 'ies'} was imported during callback.\n" |
| 572 | + "You can set `_allow_dynamic_callbacks` to allow for development purpose only." |
| 573 | + ) |
| 574 | + dist = app.get_dist(diff_packages) |
| 575 | + response["dist"] = dist |
| 576 | + |
560 | 577 | try:
|
561 | 578 | jsonResponse = to_json(response)
|
562 | 579 | except TypeError:
|
|
0 commit comments