Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute_solid fails to execute aliased configured solid with a type error #3662

Closed
antonl opened this issue Feb 9, 2021 · 1 comment
Closed
Assignees
Labels
type: bug Something isn't working type: troubleshooting Related to debugging and error messages

Comments

@antonl
Copy link

antonl commented Feb 9, 2021

Summary

I am trying to curry a solid with some default configuration, and then create an alias of that solid. This is a form of the "solid_factory" pattern. The resulting solid is a CallableNode, which cannot be run with execute_solid for some reason.

I expected to be able to use this aliasing pattern to build up a pipeline.

Reproduction

from dagster import configured, solid, execute_solid

_MESSAGE_ALIAS_KEY = "say[{message}]"


@solid(
    config_schema={
        "message": str
    }
)
def say(context, name: str) -> str:
    message = context.solid_config.get("message")
    return f"{message} {name}!"


def message_factory(message):
    @configured(say)
    def _configured(cfg):
        return {
            "message": message,
        }

    return _configured.alias(_MESSAGE_ALIAS_KEY.format(message=message))


say_hello = message_factory("hello")

result = execute_solid(say_hello, input_values={
    "name": "Dagster"
})

This yields the traceback:

Traceback (most recent call last):
  File "[...snip...]/test.py", line 28, in <module>
    result = execute_solid(say_hello, input_values={
  File "/opt/miniconda3/envs/dp-dagster/lib/python3.8/site-packages/dagster/utils/test/__init__.py", line 291, in execute_solid
    check.inst_param(solid_def, "solid_def", NodeDefinition)
  File "/opt/miniconda3/envs/dp-dagster/lib/python3.8/site-packages/dagster/check/__init__.py", line 178, in inst_param
    raise_with_traceback(
  File "/opt/miniconda3/envs/dp-dagster/lib/python3.8/site-packages/future/utils/__init__.py", line 446, in raise_with_traceback
    raise exc.with_traceback(traceback)
dagster.check.ParameterCheckError: Param "solid_def" is not a NodeDefinition. Got <dagster.core.definitions.composition.CallableNode object at 0x7fd21ca33c10> which is type <class 'dagster.core.definitions.composition.CallableNode'>.

Workaround

Workaround from @alangenfeld. The idea is to use the configured property on the solid.

from dagster import configured, solid, execute_solid

_MESSAGE_ALIAS_KEY = "say_{message}"

@solid(
    config_schema={
        "message": str
    }
)

def say(context, name: str) -> str:
    message = context.solid_config.get("message")
    return f"{message} {name}!"
def message_factory(message):
    return say.configured(
        {"message": message},
        name=_MESSAGE_ALIAS_KEY.format(message=message)
    )
say_hello = message_factory("hello")
result = execute_solid(say_hello, input_values={
    "name": "Dagster"
})

Dagit UI/UX Issue Screenshots

Additional Info about Your Environment


Message from the maintainers:

Impacted by this bug? Give it a 👍. We factor engagement into prioritization.

@antonl antonl added the type: bug Something isn't working label Feb 9, 2021
@yuhan yuhan added the type: troubleshooting Related to debugging and error messages label May 14, 2021
@dpeng817
Copy link
Contributor

Using my_solid.alias() creates a PendingNodeInvocation, which we do not support using with execute_solid, unfortunately. However, we are moving towards direct invocation as the recommended testing API for solids, and that does work with PendingNodeInvocation. You can learn more about direct invocation here.

Here is what your code example would look like using direct invocation.

from dagster import configured, solid

_MESSAGE_ALIAS_KEY = "say_{message}"


@solid(
    config_schema={
        "message": str
    }
)
def say(context, name: str) -> str:
    message = context.solid_config.get("message")
    return f"{message} {name}!"


def message_factory(message):
    @configured(say)
    def _configured(cfg):
        return {
            "message": message,
        }

    return _configured.alias(_MESSAGE_ALIAS_KEY.format(message=message))


say_hello = message_factory("hello")

assert say_hello("Dagster") == "hello Dagster!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working type: troubleshooting Related to debugging and error messages
Projects
None yet
Development

No branches or pull requests

4 participants