https://dagster.io/ logo
#ask-ai
Title
# ask-ai
m

Martin Laurent

02/06/2024, 4:26 PM
How can I write a @graph_asset that depends on another upstream asset and uses the AssetExecutionContext. I get this for now:
"context" is not a valid name in Dagster. It conflicts with a Dagster or python reserved keyword.
s

Scout

02/06/2024, 4:26 PM
Based on the documentation, when defining a
@graph_asset
, you should not use
context
as a parameter name because it conflicts with a reserved keyword in Dagster. However, it's important to note that
@graph_asset
is a composition function, and composition functions have specific semantics that do not align with the use of a context parameter. If you need to define a
@graph_asset
that depends on another upstream asset, you should specify the dependencies using the
deps
parameter without including a context parameter. Here's an example of how you might define such a dependency without using `context`:
Copy code
python from dagster import graph_asset  @graph_asset def my_upstream_asset():     # ... define the upstream asset ...     pass  @graph_asset def my_graph_asset(my_upstream_asset):     # ... define the graph asset that depends on the upstream asset ...     pass
In this example,
my_graph_asset
depends on
my_upstream_asset
, and the dependency is declared by including
my_upstream_asset
as a parameter in the definition of
my_graph_asset
. If you need to access the
AssetExecutionContext
within an asset, you would typically do this within an
@asset
-decorated function, not within a
@graph_asset
. Here's an example of how you might use
AssetExecutionContext
within an `@asset`:
Copy code
python from dagster import asset, AssetExecutionContext  @asset def my_asset(context: AssetExecutionContext):     # ... use the context to access loggers, resources, etc. ...     pass
Remember that
@graph_asset
is used to compose assets and define their dependencies, and it does not perform computation itself. If you need to perform computation and access execution context, you should use
@asset
instead.
4 Views