Skip to content

How to get the metadata or tags for the latest materialization of an asset? #14338

Answered by jamiedemaria
jamiedemaria asked this question in Q&A
Discussion options

You must be logged in to vote

The context object that's passed to functions decorated by @asset, @op, and @sensor contains an instance 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

@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

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@sryza
Comment options

Answer selected by jamiedemaria
Comment options

You must be logged in to vote
2 replies
@sryza
Comment options

@alex-orlovskyi
Comment options

Comment options

You must be logged in to vote
1 reply
@don1uppa
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area: metadata Related to metadata area: tags Related to tagging and labeling
5 participants