Brent Shulman
02/14/2024, 10:52 PMScout
02/14/2024, 10:52 PMasset_partitions_def_for_input
method within an asset to get the PartitionsDefinition
for a particular input. This method can be used to log or otherwise act upon the partition information of an input asset within the body of another asset. Here's an example from the documentation: python from dagster import AssetExecutionContext, DailyPartitionsDefinition, asset partitions_def = DailyPartitionsDefinition("2023-08-20") @asset(partitions_def=partitions_def) def upstream_asset(): ... @asset(partitions_def=partitions_def) def downstream_asset(context: AssetExecutionContext, upstream_asset): <http://context.log.info|context.log.info>(context.asset_partitions_def_for_input("upstream_asset")) # materializing the 2023-08-21 partition of this asset will log: # DailyPartitionsDefinition("2023-08-20")
In this example, both upstream_asset
and downstream_asset
are defined with the same DailyPartitionsDefinition
. When the downstream_asset
is materialized, it logs the PartitionsDefinition
of the upstream_asset
input, which is determined by the partition key of the run. This approach allows you to define how an asset's inputs should be handled based on the partition information, which can be particularly useful when dealing with partitioned assets and ensuring that the correct partitions are being used as inputs for downstream computations.