I have two assets where the number of second asset...
# ask-community
c
I have two assets where the number of second assets being generated is a function of the output of the first, what's the best way to do this?
Copy code
@asset
def get_asset_numbers() -> int:
    a_list = [1, 2, 3]
    for i in a_list:
       yeild i

@asset
def process_number(get_asset_numbers: int):
    print(f"Num: {input}")
    return input
The above should print:
Copy code
Num: 1
Num: 2
Num: 3
Is the right way to do this to have a function in the middle that calls
process_number
in a forloop?
This code currently only prints
Num: 1
and then stops.
s
Hi Charles - there's actually not currently an easy way to do this in Dagster. We'd generally recommend modeling that second asset as a single dynamically-partitioned asset, with a number for each partition. In the future, you'll be able to have a dynamically partitioned assets execute in the same runs that their partitions are generated, but this isn't currently possible.
one pattern that might work for you is dynamic graphs: https://docs.dagster.io/concepts/ops-jobs-graphs/dynamic-graphs#dynamic-graphs potentially with graph-backed assets
c
Thanks, what are the main trade-offs between modelling it as a dynamically partitioned asset vs simply as a series of ops?
s
I think the biggest relevant one here is that, as an asset, it gets to be part of the asset graph. So you can declare and observe how it relates to other assets that are upstream or downstream of it