# ask-ai

Bowen Zhang

03/06/2024, 4:46 AM
how do I provide the same Asset check to multiple assets


03/06/2024, 4:46 AM
To apply the same asset check to multiple assets, you can use check factories. Check factories allow you to write a generic check that gets parameterized with a set of assets and runs independently for each asset. However, if you want a check function that runs once and returns results for many assets, that is not currently possible. The tracking issue for this feature request is #18068 on the Dagster GitHub repository. Here's an example from the documentation that illustrates how to define multiple checks that are executed within the same function, which can be useful when loading the data for the checks is time-consuming:
Copy code
python from dagster import multi_asset_check, AssetCheckSpec, AssetCheckResult  @multi_asset_check(     check_specs=[         AssetCheckSpec("orders_id_has_no_nulls", asset=orders),         AssetCheckSpec("orders_id_is_unique", asset=orders),     ] ) def orders_checks():     orders_df = pd.read_csv("orders.csv")     num_null_order_ids = orders_df["order_id"].isna().sum()      return [         AssetCheckResult(             check_name="orders_id_has_no_nulls",             asset_key="orders",             success=(num_null_order_ids == 0),             metadata={"num_null_order_ids": num_null_order_ids},         ),         AssetCheckResult(             check_name="orders_id_is_unique",             asset_key="orders",             success=orders_df["order_id"].is_unique,         )     ]
In this example,
is a function that performs multiple checks on the
asset. Each
specifies a check to be performed, and the function returns a list of
objects, one for each check. For more details on implementing asset checks and to follow updates on the feature request for running a single check function that returns results for multiple assets, you can refer to the Dagster GitHub issues and discussions.