How to access the context variable in a graph_multi_asset #21018
-
In Dagster, how does one access the 'Context' variable within a graph_multi_asset? E.g., I have context running through the underlying ops/ assets. " base_path = Path(context.partition_key)" I can't do it though, because dagster errors with: " dagster._core.errors.DagsterInvalidDefinitionError: "context" is not a valid name in Dagster. It conflicts with a Dagster or python reserved keyword." So How does one access context metadata (per partition) within the graph_multi_asset? Thanks heaps!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
In Dagster, the To access context metadata within a If you need to access the partition key within a Here's an example of how you might access the partition key within an op that is part of a from dagster import op, graph
@op
def my_op(context):
base_path = Path(context.partition_key)
# ... your logic here ...
@graph
def my_graph():
my_op()
# Then you would define a `graph_multi_asset` that includes `my_graph` In this example, If you need to pass additional context metadata to the ops within a |
Beta Was this translation helpful? Give feedback.
In Dagster, the
context
parameter is used to pass execution-time information to assets and ops. However, when defining agraph_multi_asset
, you cannot directly usecontext
as a parameter name because it is a reserved keyword in Dagster. This is why you are encountering theDagsterInvalidDefinitionError
.To access context metadata within a
graph_multi_asset
, you should use the parameters that are passed to the underlying ops or assets. These parameters can include the partition key or other context-related information that you need.If you need to access the partition key within a
graph_multi_asset
, you would typically do so within the individual ops that make up the graph, rather than at …