예제 #1
0
def _yield_compute_results(compute_context, inputs, compute_fn):
    check.inst_param(compute_context, 'compute_context',
                     SystemComputeExecutionContext)
    step = compute_context.step
    user_event_sequence = compute_fn(SolidExecutionContext(compute_context),
                                     inputs)

    if isinstance(user_event_sequence, Output):
        raise DagsterInvariantViolationError((
            'Compute function for solid {solid_name} returned a Output rather than '
            'yielding it. The compute_fn of the core SolidDefinition must yield '
            'its results').format(solid_name=str(step.solid_handle)))

    if user_event_sequence is None:
        return

    for event in user_event_sequence:
        if isinstance(event, (Output, Materialization, ExpectationResult)):
            yield event
        else:
            raise DagsterInvariantViolationError((
                'Compute function for solid {solid_name} yielded a value of type {type_} '
                'rather than an instance of Output, Materialization, or ExpectationResult. '
                'Values yielded by solids must be wrapped in one of these types. If your '
                'solid has a single output and yields no other events, you may want to use '
                '`return` instead of `yield` in the body of your solid compute function. If '
                'you are already using `return`, and you expected to return a value of type '
                '{type_}, you may be inadvertently returning a generator rather than the value '
                'you expected.').format(solid_name=str(step.solid_handle),
                                        type_=type(event)))
예제 #2
0
def _yield_compute_results(
    step_context: StepExecutionContext, inputs: Dict[str, Any], compute_fn: Callable
) -> Iterator[SolidOutputUnion]:
    check.inst_param(step_context, "step_context", StepExecutionContext)

    user_event_generator = compute_fn(SolidExecutionContext(step_context), inputs)

    if isinstance(user_event_generator, Output):
        raise DagsterInvariantViolationError(
            (
                "Compute function for solid {solid_name} returned a Output rather than "
                "yielding it. The compute_fn of the core SolidDefinition must yield "
                "its results"
            ).format(solid_name=str(step_context.step.solid_handle))
        )

    if user_event_generator is None:
        return

    if inspect.isasyncgen(user_event_generator):
        user_event_generator = gen_from_async_gen(user_event_generator)

    for event in iterate_with_context(
        lambda: solid_execution_error_boundary(
            DagsterExecutionStepExecutionError,
            msg_fn=lambda: f'Error occurred while executing solid "{step_context.solid.name}":',
            step_context=step_context,
            step_key=step_context.step.key,
            solid_def_name=step_context.solid_def.name,
            solid_name=step_context.solid.name,
        ),
        user_event_generator,
    ):
        yield _validate_event(event, step_context.step.solid_handle)
예제 #3
0
def _yield_compute_results(step_context: StepExecutionContext,
                           inputs: Dict[str, Any],
                           compute_fn: Callable) -> Iterator[SolidOutputUnion]:
    check.inst_param(step_context, "step_context", StepExecutionContext)

    user_event_generator = compute_fn(SolidExecutionContext(step_context),
                                      inputs)

    if isinstance(user_event_generator, Output):
        raise DagsterInvariantViolationError((
            "Compute function for solid {solid_name} returned a Output rather than "
            "yielding it. The compute_fn of the core SolidDefinition must yield "
            "its results").format(
                solid_name=str(step_context.step.solid_handle)))

    if user_event_generator is None:
        return

    if inspect.isasyncgen(user_event_generator):
        user_event_generator = gen_from_async_gen(user_event_generator)

    for event in user_event_generator:
        yield _validate_event(event, step_context.step.solid_handle)
예제 #4
0
def _yield_compute_results(step_context: StepExecutionContext,
                           inputs: Dict[str, Any],
                           compute_fn: Callable) -> Iterator[SolidOutputUnion]:
    check.inst_param(step_context, "step_context", StepExecutionContext)

    user_event_generator = compute_fn(SolidExecutionContext(step_context),
                                      inputs)

    if isinstance(user_event_generator, Output):
        raise DagsterInvariantViolationError((
            "Compute function for {described_node} returned an Output rather than "
            "yielding it. The compute_fn of the {node_type} must yield "
            "its results").format(
                described_node=step_context.describe_op(),
                node_type=step_context.solid_def.node_type_str,
            ))

    if user_event_generator is None:
        return

    if inspect.isasyncgen(user_event_generator):
        user_event_generator = gen_from_async_gen(user_event_generator)

    op_label = step_context.describe_op()

    for event in iterate_with_context(
            lambda: solid_execution_error_boundary(
                DagsterExecutionStepExecutionError,
                msg_fn=lambda: f"Error occurred while executing {op_label}:",
                step_context=step_context,
                step_key=step_context.step.key,
                op_def_name=step_context.solid_def.name,
                op_name=step_context.solid.name,
            ),
            user_event_generator,
    ):
        yield _validate_event(event, step_context)
예제 #5
0
파일: compute.py 프로젝트: frantic/dagster
def _yield_compute_results(compute_context: SystemComputeExecutionContext,
                           inputs: Dict[str, Any],
                           compute_fn: Callable) -> Iterator[SolidOutputUnion]:
    check.inst_param(compute_context, "compute_context",
                     SystemComputeExecutionContext)
    step = compute_context.step
    user_event_sequence = compute_fn(SolidExecutionContext(compute_context),
                                     inputs)

    if isinstance(user_event_sequence, Output):
        raise DagsterInvariantViolationError((
            "Compute function for solid {solid_name} returned a Output rather than "
            "yielding it. The compute_fn of the core SolidDefinition must yield "
            "its results").format(solid_name=str(step.solid_handle)))

    if user_event_sequence is None:
        return

    for event in user_event_sequence:
        if isinstance(
                event,
            (DynamicOutput, Output, AssetMaterialization, Materialization,
             ExpectationResult),
        ):
            yield event
        else:
            raise DagsterInvariantViolationError((
                "Compute function for solid {solid_name} yielded a value of type {type_} "
                "rather than an instance of Output, AssetMaterialization, or ExpectationResult."
                " Values yielded by solids must be wrapped in one of these types. If your "
                "solid has a single output and yields no other events, you may want to use "
                "`return` instead of `yield` in the body of your solid compute function. If "
                "you are already using `return`, and you expected to return a value of type "
                "{type_}, you may be inadvertently returning a generator rather than the value "
                "you expected.").format(solid_name=str(step.solid_handle),
                                        type_=type(event)))