-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The latest evolution of #14931 & #15392 intentionally aligned with #15928 this PR adds support for a new "Result" return type from assets that do not deal with "Outputs" to be able to communicate materialization metadata. ## How I Tested These Changes added tests.
- Loading branch information
1 parent
bfe788c
commit 711d2e5
Showing
6 changed files
with
285 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
43 changes: 43 additions & 0 deletions
43
python_modules/dagster/dagster/_core/definitions/result.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import NamedTuple, Optional | ||
|
||
from dagster._annotations import PublicAttr, experimental | ||
|
||
from .events import ( | ||
AssetKey, | ||
CoercibleToAssetKey, | ||
) | ||
from .metadata import MetadataUserInput | ||
|
||
|
||
@experimental | ||
class MaterializeResult( | ||
NamedTuple( | ||
"_MaterializeResult", | ||
[ | ||
("asset_key", PublicAttr[Optional[AssetKey]]), | ||
("metadata", PublicAttr[Optional[MetadataUserInput]]), | ||
], | ||
) | ||
): | ||
"""An object representing a successful materialization of an asset. These can be returned from | ||
@asset and @multi_asset decorated functions to pass metadata or specify specific assets were | ||
materialized. | ||
Attributes: | ||
asset_key (Optional[AssetKey]): Optional in @asset, required in @multi_asset to discern which asset this refers to. | ||
metadata (Optional[MetadataUserInput]): Metadata to record with the corresponding AssetMaterialization event. | ||
""" | ||
|
||
def __new__( | ||
cls, | ||
*, # enforce kwargs | ||
asset_key: Optional[CoercibleToAssetKey] = None, | ||
metadata: Optional[MetadataUserInput] = None, | ||
): | ||
asset_key = AssetKey.from_coercible(asset_key) if asset_key else None | ||
|
||
return super().__new__( | ||
cls, | ||
asset_key=asset_key, | ||
metadata=metadata, # check? | ||
) |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.