Stephen Bailey
08/24/2022, 1:59 PMassets_list = []
for ii in [1, 2, 3]:
@asset(name=["my_asset", f"model_{ii}"])
def _generated_asset():
return ii
assets_list.append(_generated_asset)
and i want to reference it in another file
from .asset_list_file import assets_list
asset_1 = assets_list[0]
asset_2 = assets_list[1]
@asset
def my_downstream_asset(asset_1, asset_2):
return asset_1 + asset_2
But I'm getting a variety of errors related to asset_1
not being created, etc. I've tried creating new SourceAssetes
that reference the assets in the first file. The cross-repository example here seems to be what I want, but I can't directly import the AssetDefinition, because it's being dynamically generated.
Its just really unclear to me what the relationship is between asset keys, the input arguments for assets, how to do AssetSelections. It seems like there's some under-the-hood relationship between the variable name and the inputs. Is there a recommended way for me to approach this problem?Stephen Bailey
08/24/2022, 2:05 PMins
when injecting dynamically generated asset definitions
from dagster import AssetKey, AssetIn
asset1_key = AssetKey(["my_asset", "model_1"])
asset2_key = AssetKey(["my_asset", "model_2"])
@asset(ins={"asset_1": AssetIn(asset1_key), "asset_2": AssetIn(asset2_key)})
def my_downstream_asset(asset_1, asset_2):
return asset_1 + asset_2
sandy
08/24/2022, 4:00 PMassets_list = []
for ii in [1, 2, 3]:
@asset(name="model_{ii}")
def _generated_asset():
return ii
assets_list.append(_generated_asset)
@asset
def my_downstream_asset(model_1, model_2):
return model_1 + model_2
• when an has a multi-segment key, like in your case, you need to use `AssetIn`sStephen Bailey
08/24/2022, 5:41 PM__
like my_asset__model_1
, but that doesn't appear to be the case