https://dagster.io/ logo
#ask-community
Title
# ask-community
b

bx2

07/24/2023, 1:19 PM
hi all, while using dynamic partitions, are sensors the only way to populate them? if yes, i have an asset_sensor, i.e. i want to populate the partition values based on an asset. how do i access contents of the asset within the asset_sensor?
🤖 1
g

Guy McCombe

07/24/2023, 1:32 PM
No, you can populate them pretty much anywhere afaik. I'm not sure if this is a recommended practice, but you can do it from within an asset for example:
Copy code
if not context.instance.has_dynamic_partition(
    dynamic_partition_defs.name, candidate_partition
):
    context.instance.add_dynamic_partitions(
        dynamic_partition_defs.name, [candidate_partition]
    )
b

bx2

07/24/2023, 1:34 PM
aye, i figured if i would use a sensor i would have to load the data manually as i can't see anything in the implementation of the sensor context to offer direct access to the asset that triggered it. i guess, populating it from within the asset itself (speaking of the upstream asset) makes more sense - was just not sure about the best practice.
g

Guy McCombe

07/24/2023, 1:35 PM
Yeah I had the same issue and went with populating in the upstream asset code. Obviously not as tolerant to failure as a sensor, would be interested to hear if someone has a better solution 😅
b

bx2

07/24/2023, 1:35 PM
haha aye :))
36 Views