Does anyone know how I can get asset metadata from...
# ask-community
j
Does anyone know how I can get asset metadata from
RunFailureSensorContext
? I'd like to use some of the metadata in a Slack alert.
dagster bot answered by content 1
Copy code
def fail_message_block_builder(context: RunFailureSensorContext):
  ... # my custom message slack block builder where I would like to get my 'owner' key/value from the asset metadata 

make_slack_on_run_failure_sensor(
    channel="#dagster-alerts",
    slack_token=slack_resource.token,
    blocks_fn=fail_message_block_builder
)
c
Hi Jonathan. Anywhere where you have access to the instance, you can fetch the materializations and metadata from the instance: https://github.com/dagster-io/dagster/discussions/7429
j
Thanks Claire!
Hey @claire that approach you sent only works if the materialization was successful and so there are asset materializations appearing in the event records. In my case, the asset materialization wasn't successful. Is there a way to simply retrieve a list of assets filtered by an asset_key to get the asset.metadata?
@Timothee Vandeput Curious to know if you happen to know of a solution for the above problem? I’m trying to do Slack alerts when asset materialization fails, and I want to use dagster’s
metadata
field to tag owners in the slack message, similar to how I’m tagging you now.
t
@Jonathan Neo haven't done that yet 👀
👍 1
j
No worries then 🙂
@claire by the way, I’ve tried
instance.get_asset_records(asset_keys=asset_keys)
, but the
AssetEntry
returned doesn’t contain any
metadata
fields:
Copy code
AssetEntry(asset_key=AssetKey(['python_example', 'something']), last_materialization_record=None, last_run_id='1c2e2ec5-b059-446c-9815-f5126edd2ca8', asset_details=None, cached_status=None))]
Maybe
asset_details
should’ve shown something and not
None
?
c
Hi Jonathan--I think I misunderstood your original question. I believe you were referring to the metadata specified on
@asset
i.e.
@asset(metadata={"owner": ....})
but I was referring to the metadata attached to a given output. You could fetch the asset definition directly from the
Definitions
object, but for a run failure sensor the
Definitions
object is unfortunately not available on the context. I believe the regular
SensorEvaluationContext
used for regular
@sensor
contains a
context.definitions
field, so you could create a
@sensor
object that basically does the same thing as a run failure sensor