Using get_last_partition_key with Partition Loading Context
Last updated: October 28, 2025
Problem Description
The get_last_partition_key function requires a partition loading context when used with a current_time parameter. This change affects users who rely on this function in schedule execution functions to find partitions to trigger at scheduled execution times.
Symptoms
Errors when using
get_last_partition_keywithcurrent_timeparameterFailed schedule execution functions that depend on finding the latest partition
Root Cause
The current_time argument was removed from get_last_partition_key as it was not part of the public API. The function now requires a partition loading context to properly determine the last partition key.
Solution
Wrap the get_last_partition_key call with a partition_loading_context
import datetime
import dagster as dg
from dagster._core.definitions.partitions.context import partition_loading_context
partitions_def = dg.DailyPartitionsDefinition(start_date="2025-01-01")
with partition_loading_context(effective_dt=datetime.datetime(2025, 1, 2)):
print(partitions_def.get_last_partition_key()) # 2025-01-01Step-by-Step Resolution
Import the required context manager from dagster (Note: In upcoming releases, this will be available from the top-level
dagstermodule)Wrap your
get_last_partition_keycall with the context managerPass the desired timestamp using the
effective_dtparameter
Alternative Solutions
While get_partition_key_for_timestamp is available, it may return keys for non-existent partitions and requires additional validation code.
Prevention
Always use the partition loading context when working with partition keys that depend on specific timestamps.
Related Documentation