Martin Laurent
02/22/2024, 2:29 PMScout
02/22/2024, 2:29 PMpython from dagster import graph, op @op def my_op(x: int): return x + 1 @graph def my_graph(x: int = 10): return my_op(x)
In this example, the my_graph
graph has an input x
with a default value of 10
. If no value is provided for x
when the graph is invoked, it will use the default value of 10
. This allows you to have optional inputs for your graphs in Dagster.Martin Laurent
02/22/2024, 2:30 PMScout
02/22/2024, 2:30 PMins
parameter to specify inputs. However, the ins
parameter itself does not directly support default values as you would define them in a Python function signature. Instead, the ins
parameter is used to define the metadata and dependencies for the inputs of an asset or op. If you want to provide a default value for an input when using the ins
parameter, you would typically handle this within the body of the op or function that is being called. Here's an example of how you might do this: python from dagster import op, In, graph @op(ins={"input1": In()}) def my_op(context, input1=None): if input1 is None: input1 = "default_value" # Set the default value here # Your op logic here @graph def my_graph(): my_op() # Called without providing input1, so it will use the default value
In this example, my_op
is defined with an input input1
that uses the In
class to specify its metadata. The default value for input1
is handled within the body of my_op
by checking if input1
is None
and setting it to a default value if necessary. This approach allows you to define a default behavior for when an input is not provided, but it's important to note that the ins
parameter itself is not where you define default values. Instead, it's used to specify the input definitions for assets or ops, and the defaulting logic is handled within the op or function.Martin Laurent
02/22/2024, 2:31 PMScout
02/22/2024, 2:31 PMins={In(...)}
syntax when defining a graph. The In
class is used to specify metadata about an input, such as its description, dagster_type, and whether it is required, but not to assign a default value. If you want to provide a default value for an input in a graph, you would typically handle this within the body of the ops that make up the graph. Each op can have logic to provide a default value if none is supplied. Here's an example of how you might handle this: python from dagster import op, In, graph @op def process_data(data: int): # Op logic here return data @graph def my_graph(input1: int = 10): process_data(input1) # When invoking the graph, if you don't provide input1, it will default to 10 result = my_graph.execute_in_process()
In this example, my_graph
has a parameter input1
with a default value of 10
. If input1
is not provided when the graph is invoked, it will use the default value. If you need to use the ins={In(...)}
syntax for some reason, such as when you are defining a graph without using the decorator syntax, you would still need to handle default values within the ops or by using a config schema that provides defaults. The In
class itself does not provide a mechanism for default values. Please note that Dagster's features and capabilities are subject to change, and it's always a good idea to consult the latest Dagster documentation or release notes for the most current information.