Hi Dagster Team, If I give an asset materializatio...
# ask-community
s
Hi Dagster Team, If I give an asset materialization a metadata entry, what's the easiest way to access those values? E.g.
Copy code
# in some op
context.log_event(
            AssetMaterialization(
                asset_key=AssetKey("foo"),
                description="Persisted result to storage.",
                metadata={
                     "text_metadata": "Text-based metadata for this event",
                }
            )
        )

# in a sensor (or op execution context)
foo_event_records = context.instance.get_event_records(
            EventRecordsFilter(
                event_type=DagsterEventType.ASSET_MATERIALIZATION,
                asset_key=AssetKey(["foo"]),
            ),
            ascending=False,
        )

# get text_metadata from return foo_event_records
When I print out the event records, I can see the stored metadata values for each event record, but I don't want to parse that text, if there's an easy helper function that will get me the metadata values easily?
j
Hey @Selene Hines the return from
get_event_records
is a list of
EventLogRecord
s. which in turn have a property
asset_materialization
which should reconstruct the materialization with the metadata. so i think something like this would work
Copy code
foo_event_records = context.instance.get_event_records(
            EventRecordsFilter(
                event_type=DagsterEventType.ASSET_MATERIALIZATION,
                asset_key=AssetKey(["foo"]),
            ),
            ascending=False,
        )

for event in foo_event_records:
    metadata = event.asset_materialization.metadata
    # whatever you want to do with the metadata
let me know how that goes for you!
s
Thank you very much! 🙂