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

Martin Laurent

02/14/2024, 3:27 PM
Is it possible in an asset, to access the metadata of its upstream dependency materializations?
s

Scout

02/14/2024, 3:27 PM
There was an error processing your request. Please try again.
m

Martin Laurent

02/14/2024, 3:34 PM
@Scout Is it possible in an asset, to access the metadata of its upstream dependency materializations?
s

Scout

02/14/2024, 3:34 PM
Yes, it is possible to access the metadata of an upstream dependency's materializations within an asset. The documentation provides an example of how to do this:
Copy code
python @asset def downstream_asset(context, upstream_asset):     latest_observation_record = context.instance.get_event_records(         EventRecordsFilter(             event_type=DagsterEventType.ASSET_OBSERVATION,             asset_key=AssetKey(["upstream_asset"]),         ),         ascending=False,         limit=1,     )[0]     metadata = latest_observation_record.event_log_entry.dagster_event.event_specific_data.asset_observation.metadata
In this example, the
downstream_asset
function uses the
context.instance.get_event_records
method to query the event log for the latest observation event related to the
upstream_asset
. It then extracts the metadata from this event record. This allows the downstream asset to access and potentially use the metadata from the upstream asset's materialization within its computation.
m

Martin Laurent

02/14/2024, 3:36 PM
@Scout is it possible to do this for a particular partition key?
s

Scout

02/14/2024, 3:36 PM
There was an error processing your request. Please try again.
6 Views