https://dagster.io/ logo
#ask-community
Title
# ask-community
g

Guanghua Yang

05/09/2023, 10:38 PM
Hello, if defined my asset as follow:
Copy code
@asset(group_name='group1',
       metadata={"owner":"Gavin Yang"})
def topstory_ids():
	newstories_url = "<https://hacker-news.firebaseio.com/v0/topstories.json>"
	top_new_story_ids = requests.get(newstories_url).json()[:100]
	return top_new_story_ids
And I want to retrieve the ‘metadata’ field I passed in, how should I do this? Appreciate for any help!
dagster bot responded by community 1
l

Le Yang

05/09/2023, 11:03 PM
The metadata in the decorator is about the decorated function. If you want to use it inside the function you should use config map or a factory function instead.
g

Guanghua Yang

05/09/2023, 11:30 PM
I do not mean using that value inside the function. Instead, I want to create a run_failure_sensor that listen on the failure job. Once a job fail, I want to retrieve which asset the step fails, and then retrieve the ‘owner’ from the asset metadata field. I tried to use instance.get_asset_records(), but it seems like it does not contain the metadata field I passed into the decorator.
l

Le Yang

05/09/2023, 11:44 PM
I'm not at home to check, I'd think run status sensor context or event would get you to the asset/op definition to retrieve the metadata associated with the failed run. Following.
💡 1
g

Guanghua Yang

05/10/2023, 2:24 PM
Hi, I have checked the run_status_sensor as well as RunStatusSensorContext, but still not sure how to retrieve the metadata associated with asset/op definition.
l

Le Yang

05/10/2023, 2:27 PM
Bummer. Maybe some Dagster engineer can chime in. I'd hate having to query the database for such information. Did you by chance check if you can access metadata recorded in the Output?
g

Guanghua Yang

05/10/2023, 2:30 PM
Yes, if the asset return Output at end with a ‘metadata’ field inside, then I see the metadata of each success asset using get_run_records(), but it still does not contain the metadata specified in the asset definition.
2 Views