Created
June 25, 2024 19:59
-
-
Save cmpadden/0a5ce71637944319240df3264c12e8f1 to your computer and use it in GitHub Desktop.
Dagster: Example of `@asset_check` with custom `IOManager`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| USAGE | |
| $ dagster dev -f example-asset-check-iomanager.py | |
| """ | |
| from dagster import ( | |
| AssetCheckResult, | |
| Definitions, | |
| InputContext, | |
| IOManager, | |
| OutputContext, | |
| asset, | |
| asset_check, | |
| io_manager | |
| ) | |
| class MyIOManager(IOManager): | |
| def handle_output(self, context: OutputContext, obj): | |
| pass | |
| def load_input(self, context: InputContext): | |
| return "loaded_data" | |
| @io_manager | |
| def my_io_manager(): | |
| return MyIOManager() | |
| @asset(io_manager_key="my_io_manager") | |
| def my_asset(): | |
| return [1, 2, 3] | |
| @asset_check(asset=my_asset) | |
| def my_asset_check(my_asset): | |
| # `my_asset` is of value `loaded_data` from IOManager | |
| passed = my_asset == [1, 2, 3] | |
| return AssetCheckResult(passed=passed) | |
| defs = Definitions( | |
| assets=[my_asset], | |
| asset_checks=[my_asset_check], | |
| resources={"my_io_manager": my_io_manager} | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment