https://dagster.io/ logo
#ask-ai
Title
# ask-ai
e

elgreco

03/05/2024, 2:04 PM
How can I prefix the inputs from assets in the function definition by using load_assets_from_modules? Currently it only prefixes the asset itself but not the upstream assets
s

Scout

03/05/2024, 2:04 PM
When using
load_assets_from_modules
to load assets, the function allows you to specify a
key_prefix
that will be prepended to the keys of the loaded assets. However, based on the documentation, there is no direct parameter provided by
load_assets_from_modules
that automatically prefixes the keys of upstream assets that are inputs to the loaded assets. To ensure that the upstream assets have the correct prefixed keys, you would need to handle the prefixing manually. This means that when defining your assets, you should explicitly set the
key
parameter for each
AssetIn
to include the desired prefix. Here's an example of how you might define an asset with prefixed input keys:
Copy code
python from dagster import asset, AssetIn  @asset(     ins={         "input_asset": AssetIn(key=["my_prefix", "input_asset_name"])     } ) def my_asset(input_asset):     # Your asset logic here     ...
In this example,
input_asset
is an upstream asset, and we are explicitly setting its key with the prefix
"my_prefix"
. If you are loading assets from a module and want to apply a prefix to both the assets and their upstream dependencies, you would need to ensure that the assets are defined with the appropriate prefixed keys as shown above. Then, when you use
load_assets_from_modules
, the
key_prefix
you provide will apply to the assets being loaded, and the upstream assets will already have the correct prefixes as defined in their
AssetIn
specifications. If you encounter issues where the upstream assets' keys are not being prefixed as expected, this might be a limitation or a bug in the current implementation of
load_assets_from_modules
. In such cases, you may want to check the GitHub Issues for Dagster to see if there are any known issues or feature requests related to this behavior.
2 Views