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

Yang

10/26/2022, 6:03 PM
I have another question about using partitions with assets. What's the partition field that can be accessed inside the asset?
context.partition_key
?
j

jamie

10/26/2022, 6:15 PM
to clarify, are you asking what attribute to get off the context to find the partition? or what value
context.partition_key
will have?
y

Yang

10/26/2022, 6:39 PM
yeah just what attribute
is it just partition_key?
j

jamie

10/26/2022, 7:16 PM
yeah
context.partition_key
will work. you can also use
context.asset_partition_key_for_output(<output_name>)
y

Yang

10/26/2022, 7:50 PM
oh, is that so that a different asset can still access the partition key for an upstream asset?
j

jamie

10/26/2022, 7:56 PM
i’m not totally sure - @claire can you confirm?
c

claire

10/26/2022, 8:54 PM
Ah, the function that will give you partition key of the input that maps to the current asset is the
asset_partition_key_for_input
function. Both methods that jamie mentioned pretty much do the same thing for SDAs--fetching the partition key for the current asset. The
asset_partition_key_for_output
method exists separately because some users use a pre-SDA experimental feature where a partitions definition exists directly on an output.
y

Yang

10/26/2022, 11:09 PM
oh ok great, thanks!
sorry, can you point me to the documentation for this? I can't find it. it's like this?
Copy code
@asset(partitions_def=mypartition)
def part_asset(context):
    datestr = context.asset_partition_key_for_input()
update: I used
context.partition_key
and that worked
c

claire

10/28/2022, 6:14 PM
ah, glad it worked! sorry about the late response--the documentation for the
asset_partition_key_for_input
is here: https://docs.dagster.io/_apidocs/execution#dagster.OpExecutionContext
context.partition_key
will return the output partition key of your asset.
asset_partition_key_for_input
will return partition key of the upstream input that the current asset depends on. So for example, if your current asset is an hourly-partitioned asset that depends on a daily-partitioned asset,
context.partition_key
will return an hourly-partitioned key, while
asset_partition_key_for_input
will return a daily-partitioned key.
y

Yang

10/28/2022, 8:33 PM
thank you!
gotcha, that's really helpful