Skip to content

Commit

Permalink
Make asset related checks more robust (#8008)
Browse files Browse the repository at this point in the history
op_config may be a non-iterable type. Those functions should not fail in
that case.
  • Loading branch information
aroig committed May 23, 2022
1 parent abac74a commit d9133bb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions python_modules/dagster/dagster/core/execution/context/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
from .hook import HookContext


def is_iterable(obj: Any) -> bool:
try:
iter(obj)
except:
return False
return True


class IPlanContext(ABC):
"""Context interface to represent run information that does not require access to user code.
Expand Down Expand Up @@ -680,7 +688,8 @@ def op_config(self) -> Any:

def has_asset_partitions_for_input(self, input_name: str) -> bool:
op_config = self.op_config
if op_config is not None and "assets" in op_config:

if is_iterable(op_config) and "assets" in op_config:
all_input_asset_partitions = op_config["assets"].get("input_partitions")
if all_input_asset_partitions is not None:
this_input_asset_partitions = all_input_asset_partitions.get(input_name)
Expand All @@ -691,7 +700,7 @@ def has_asset_partitions_for_input(self, input_name: str) -> bool:

def asset_partition_key_range_for_input(self, input_name: str) -> PartitionKeyRange:
op_config = self.op_config
if op_config is not None and "assets" in op_config:
if is_iterable(op_config) and "assets" in op_config:
all_input_asset_partitions = op_config["assets"].get("input_partitions")
if all_input_asset_partitions is not None:
this_input_asset_partitions = all_input_asset_partitions.get(input_name)
Expand All @@ -714,7 +723,7 @@ def asset_partition_key_for_input(self, input_name: str) -> str:

def has_asset_partitions_for_output(self, output_name: str) -> bool:
op_config = self.op_config
if op_config is not None and "assets" in op_config:
if is_iterable(op_config) and "assets" in op_config:
all_output_asset_partitions = op_config["assets"].get("output_partitions")
if all_output_asset_partitions is not None:
this_output_asset_partitions = all_output_asset_partitions.get(output_name)
Expand All @@ -725,7 +734,7 @@ def has_asset_partitions_for_output(self, output_name: str) -> bool:

def asset_partition_key_range_for_output(self, output_name: str) -> PartitionKeyRange:
op_config = self.op_config
if op_config is not None and "assets" in op_config:
if is_iterable(op_config) and "assets" in op_config:
all_output_asset_partitions = op_config["assets"].get("output_partitions")
if all_output_asset_partitions is not None:
this_output_asset_partitions = all_output_asset_partitions.get(output_name)
Expand Down

0 comments on commit d9133bb

Please sign in to comment.