Emitting MaterializeResult
whilst returning a value
#26198
-
ContextContextHistorically Dagster allows returning assets directly in its definition: @asset
def my_asset():
return "Hello, world!" although in the past year the above pattern is less recommended, in-lieu of each asset responsible for serialization & deserialization: @asset
def table():
df = ...
df.to_csv("...")
@asset(deps=[table])
def downstream1():
df = pd.read_csv("...")
... If I were to guess, this is to prevent anti-patterns like loading a massive table from the warehouse and passing it between assets. That said, it feels redundant to have each dependent asset worry about (de)serialization and knowledge of that upstream asset's internals. In any case, I see that ProblemIn the process of onboarding team members onto Dagster, we ran into the following use case (simplified): @asset
def latest_data_load_date():
latest_date = "..."
yield MaterializeResult(metadata={"latest_data_load_date": MetadataValue.timestamp(latest_date)})
return latest_date
@asset
def downstream(latest_data_load_date: str):
... We have two intentions with
The Error stack trace
Further investigation show that the plumbing between assets are broken with the use of And so, we have to choose between fulfilling either of our requirements for the asset, but not both. So the asks are:
Other users also have the same question, so it would be nice to gain clarification on proper usage / composition of these APIs. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can switch from
will follow up on the right place to put this in the docs |
Beta Was this translation helpful? Give feedback.
You can switch from
MaterializeResult
toOutput
when you want to return a value in addition tometadata
will follow up on the right place to put this in the docs