How to get the metadata or tags for the latest materialization of an asset? #14338
-
Versions of this question that come up:
Additionally, how can I get the tags from the latest materialization of an asset? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
The If you're running code outside of an asset, op, or sensor, you can access the instance by using Example of how to access metadata from a historical materialization of one asset from inside another assetUnpartitioned@asset
def asset1():
return Output(value=..., metadata={"num_rows": 5})
@asset # or op
def asset_1_num_rows(context):
instance = context.instance
materialization = instance.get_latest_materialization_event(AssetKey(["asset1"])).asset_materialization
return materialization.metadata["num_rows"] Partitionedfrom dagster import (
asset,
StaticPartitionsDefinition,
EventRecordsFilter,
AssetKey,
Output,
DagsterEventType,
)
@asset(partitions_def=StaticPartitionsDefinition(["a", "b"]))
def asset1():
return Output(value=..., metadata={"num_rows": 5})
@asset # or op
def asset1_a_num_rows(context):
instance = context.instance
materialization = instance.get_event_records(
event_records_filter=EventRecordsFilter(
event_type=DagsterEventType.ASSET_MATERIALIZATION,
asset_key=AssetKey(["asset1"]),
asset_partitions=["a"],
),
limit=1,
)[0].asset_materialization
return materialization.metadata["num_rows"] Note that you can also get previous materializations metadata of an asset in the implementation of the same assetUnpartitioned example @asset
def asset1(context):
instance = context.instance
materialization = instance.get_latest_materialization_event(AssetKey(["asset1"])).asset_materialization
previous_num_rows = materialization.metadata["num_rows"]
return Output(value=..., metadata={"num_rows": 5}) |
Beta Was this translation helpful? Give feedback.
-
Hi, @sryza, @jamiedemaria. |
Beta Was this translation helpful? Give feedback.
-
Hey @jamiedemaria, I tried all of this and it didn't worked. Than I focus on the terminology and I think I found out why this didn't work for me. When you say get the Is it possible to also retrieve the I'm trying to create my own alerts sensor and triage alerts based on the teams which they belong, and the only available field I can think of are tags, metadata or owners, but those didn't seem available with the context. @asset(
op_tags={
"kind": "python",
"severity": "critical",
"owner_tag": "DE",
},
owners=["team:DE"],
metadata={
"owner": "[email protected]",
"priority": "high",
},
)
def my asset():
return 1 Are any of the elements listed in the asset above code is retrievable from a sensor after a run failure or a run success? Thank you |
Beta Was this translation helpful? Give feedback.
The
context
object that's passed to functions decorated by@asset
,@op
, and@sensor
contains aninstance
attribute that can query the Dagster event log.If you're running code outside of an asset, op, or sensor, you can access the instance by using
DagsterInstance.get()
: #12808.Example of how to access metadata from a historical materialization of one asset from inside another asset
Unpartitioned