Skip to content

How do I check whether a particular asset partition is materialized? #16132

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

You must be logged in to vote

This should work:

from dagster import DagsterInstance, EventRecordsFilter, DagsterEventType, AssetKey


def _is_partition_materialized(
    asset_key: AssetKey, partition_key: str, instance: DagsterInstance
) -> bool:
    return bool(
        instance.get_event_records(
            EventRecordsFilter(
                asset_key=asset_key,
                event_type=DagsterEventType.ASSET_MATERIALIZATION,
                asset_partitions=[partition_key],
            ),
            limit=1,
        )
    )

You can get the instance using context.instance inside any Dagster function that accepts a context object.

Replies: 1 comment

Comment options

sryza
Aug 28, 2023
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by sryza
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant