Skip to content

Commit d5bc507

Browse files
prhaclaude
andcommitted
Pass dynamic_partitions_store to has_partition_key for DynamicPartitionsDefinition and MultiPartitionsDefinition
Fixed issue where DynamicPartitionsDefinition.has_partition_key was being called without the required dynamic_partitions_store parameter, causing tests to fail with "The instance is not available to load partitions" error. Changes: 1. Updated MultiPartitionsDefinition.has_partition_key to accept current_time and dynamic_partitions_store parameters, passing them through to DynamicPartitionsDefinition dimensions 2. Updated run_domain._get_planned_partitions to pass dynamic_partitions_store when checking has_partition_key for both DynamicPartitionsDefinition and MultiPartitionsDefinition This ensures dynamic partitions can access the instance to load partition keys, whether they're used directly or as dimensions in multi-partitions. Fixes: test_dynamic_partitioned_run, test_unfetched_partitioned_events_are_unconsumed, test_assets (dynamic_asset_partitions) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 33ba92c commit d5bc507

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

python_modules/dagster/dagster/_core/definitions/partitions/definition/multi.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,16 @@ def get_partitions_def_for_dimension(self, dimension_name: str) -> PartitionsDef
190190
check.failed(f"Invalid dimension name {dimension_name}")
191191

192192
# We override the default implementation of `has_partition_key` for performance.
193-
def has_partition_key(self, partition_key: Union[MultiPartitionKey, str]) -> bool:
193+
def has_partition_key(
194+
self,
195+
partition_key: Union[MultiPartitionKey, str],
196+
current_time: Optional[datetime] = None,
197+
dynamic_partitions_store: Optional["DynamicPartitionsStore"] = None,
198+
) -> bool:
199+
from dagster._core.definitions.partitions.definition.dynamic import (
200+
DynamicPartitionsDefinition,
201+
)
202+
194203
if isinstance(partition_key, str):
195204
try:
196205
partition_key = self.get_partition_key_from_str(partition_key)
@@ -204,9 +213,19 @@ def has_partition_key(self, partition_key: Union[MultiPartitionKey, str]) -> boo
204213
)
205214

206215
for dimension in self.partitions_defs:
207-
if not dimension.partitions_def.has_partition_key(
208-
partition_key.keys_by_dimension[dimension.name]
209-
):
216+
# For DynamicPartitionsDefinition, pass the dynamic_partitions_store
217+
if isinstance(dimension.partitions_def, DynamicPartitionsDefinition):
218+
has_key = dimension.partitions_def.has_partition_key(
219+
partition_key.keys_by_dimension[dimension.name],
220+
current_time=current_time,
221+
dynamic_partitions_store=dynamic_partitions_store,
222+
)
223+
else:
224+
has_key = dimension.partitions_def.has_partition_key(
225+
partition_key.keys_by_dimension[dimension.name]
226+
)
227+
228+
if not has_key:
210229
return False
211230
return True
212231

python_modules/dagster/dagster/_core/instance/runs/run_domain.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,20 @@ def _get_planned_partitions(
954954
f" {PARTITION_NAME_TAG}"
955955
)
956956

957-
partitions_def = asset_graph.get(asset_key_or_check_key).partitions_def
957+
# Get the node from the asset graph - handle both AssetKey and AssetCheckKey
958+
if isinstance(asset_key_or_check_key, AssetKey):
959+
node = self._get_repo_scoped_asset_node(
960+
asset_graph, asset_key_or_check_key, dagster_run.remote_job_origin
961+
)
962+
else:
963+
# For AssetCheckKey, check if it exists before trying to get it
964+
node = (
965+
asset_graph.get(asset_key_or_check_key)
966+
if asset_graph.has(asset_key_or_check_key)
967+
else None
968+
)
969+
970+
partitions_def = node.partitions_def if node else None
958971
partitions_subset = None
959972
individual_partitions = None
960973
if partition_range_start or partition_range_end:
@@ -985,8 +998,13 @@ def _get_planned_partitions(
985998
PartitionKeyRange(partition_range_start, partition_range_end),
986999
)
9871000
elif partitions_def and partition_tag:
988-
# For DynamicPartitionsDefinition, we need to pass the instance to check partition existence
989-
if isinstance(partitions_def, DynamicPartitionsDefinition):
1001+
# For DynamicPartitionsDefinition and MultiPartitionsDefinition (which may contain dynamic dimensions),
1002+
# we need to pass the instance to check partition existence
1003+
from dagster._core.definitions.partitions.definition.multi import (
1004+
MultiPartitionsDefinition,
1005+
)
1006+
1007+
if isinstance(partitions_def, (DynamicPartitionsDefinition, MultiPartitionsDefinition)):
9901008
has_key = partitions_def.has_partition_key(
9911009
partition_tag, dynamic_partitions_store=self._instance
9921010
)

0 commit comments

Comments
 (0)