Prepare the response object based on the callback output.
(
output_value,
output_spec,
multi,
response: CallbackExecutionResponse,
callback_ctx,
app,
original_packages,
background,
has_update,
has_output,
output,
callback_id,
allow_dynamic_callbacks,
)
| 579 | |
| 580 | # pylint: disable=too-many-branches |
| 581 | def _prepare_response( |
| 582 | output_value, |
| 583 | output_spec, |
| 584 | multi, |
| 585 | response: CallbackExecutionResponse, |
| 586 | callback_ctx, |
| 587 | app, |
| 588 | original_packages, |
| 589 | background, |
| 590 | has_update, |
| 591 | has_output, |
| 592 | output, |
| 593 | callback_id, |
| 594 | allow_dynamic_callbacks, |
| 595 | ): |
| 596 | """Prepare the response object based on the callback output.""" |
| 597 | component_ids: dict = collections.defaultdict(dict) |
| 598 | |
| 599 | if has_output: |
| 600 | if not multi: |
| 601 | output_value, output_spec = [output_value], [output_spec] |
| 602 | flat_output_values = output_value |
| 603 | else: |
| 604 | if isinstance(output_value, (list, tuple)): |
| 605 | # For multi-output, allow top-level collection to be |
| 606 | # list or tuple |
| 607 | output_value = list(output_value) |
| 608 | if NoUpdate.is_no_update(output_value): |
| 609 | flat_output_values = [output_value] |
| 610 | else: |
| 611 | # Flatten grouping and validate grouping structure |
| 612 | flat_output_values = flatten_grouping(output_value, output) |
| 613 | |
| 614 | if not NoUpdate.is_no_update(output_value): |
| 615 | _validate.validate_multi_return( |
| 616 | output_spec, flat_output_values, callback_id |
| 617 | ) |
| 618 | |
| 619 | for val, spec in zip(flat_output_values, output_spec): |
| 620 | if NoUpdate.is_no_update(val): |
| 621 | continue |
| 622 | for vali, speci in ( |
| 623 | zip(val, spec) if isinstance(spec, list) else [[val, spec]] # type: ignore[reportArgumentType] |
| 624 | ): |
| 625 | if not NoUpdate.is_no_update(vali): |
| 626 | has_update = True |
| 627 | id_str = stringify_id(speci["id"]) |
| 628 | prop = clean_property_name(speci["property"]) |
| 629 | component_ids[id_str][prop] = vali |
| 630 | |
| 631 | else: |
| 632 | if output_value is not None: |
| 633 | raise InvalidCallbackReturnValue( |
| 634 | f"No-output callback received return value: {output_value}" |
| 635 | ) |
| 636 | |
| 637 | if not background: |
| 638 | has_update = _set_side_update(callback_ctx, response) or has_output |
no test coverage detected
searching dependent graphs…