https://dagster.io/ logo
#dagster-feedback
Title
# dagster-feedback
s

Stephen Bailey

08/24/2022, 1:59 PM
Getting stuck trying to use assets. I have one file that generates assets:
Copy code
assets_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
Copy code
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?
ahhhhh, i think i have it now. have to use the
ins
when injecting dynamically generated asset definitions
Copy code
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
s

sandy

08/24/2022, 4:00 PM
hey @Stephen Bailey - glad you were able to figure it out. there are a couple things going on here: • the input matching is based on the asset key/name, not the variable name. so this should work:
Copy code
assets_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`s
s

Stephen Bailey

08/24/2022, 5:41 PM
gotcha, thanks. it was a little confusing because in the ui, it appears that you can reference the multi-part asset keys by joining with
__
like
my_asset__model_1
, but that doesn't appear to be the case