Utku Somer
03/06/2024, 12:46 PMScout
03/06/2024, 12:46 PMUtku Somer
03/06/2024, 12:51 PMScout
03/06/2024, 12:51 PMAssetCheckResult
with a failure condition. Here's an example of how you can define an asset check that returns a failure: python from dagster import asset, AssetCheckResult, AssetCheckSeverity @asset def my_asset(): # Your asset computation logic here ... @asset_check(asset=my_asset) def my_check(context, my_asset): # Your custom check logic here is_valid = ... # Replace with your validation logic if not is_valid: return AssetCheckResult( passed=False, severity=AssetCheckSeverity.ERROR, # Use WARN for non-blocking issues metadata={"reason": "Validation failed due to ..."}, # Optional metadata ) else: return AssetCheckResult(passed=True)
In this example, my_check
is an asset check associated with my_asset
. The check performs some validation logic and returns an AssetCheckResult
indicating whether the check passed or failed. If the check fails, you can set the severity to ERROR
and provide additional metadata to describe the failure. Please note that the severity level (ERROR
or WARN
) does not impact the execution of the asset or downstream assets. It is used to determine how the check result appears in the UI. If you want to prevent downstream assets from materializing based on the result of an asset check, you would need to implement custom logic to handle this, as Dagster's default behavior is to block downstream materializations only if an upstream asset fails to compute, not if an asset check fails. For the most up-to-date information on asset checks and handling failures, please refer to the latest Dagster documentation.