I have another question about using partitions wit...
# ask-community
y
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
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
yeah just what attribute
is it just partition_key?
j
yeah
context.partition_key
will work. you can also use
context.asset_partition_key_for_output(<output_name>)
y
oh, is that so that a different asset can still access the partition key for an upstream asset?
j
i’m not totally sure - @claire can you confirm?
c
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
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
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
thank you!
gotcha, that's really helpful