Skip to content

Commit

Permalink
Support asset backfills in UI that target only unpartitioned assets (#…
Browse files Browse the repository at this point in the history
…18352)

Fixes #15173

Previously, a graphQL error would be raised when attempting to display a
backfill that targets only unpartitioned assets. This is because we
assumed in a resolver that at least 1 partition would be targeted.

This PR fixes the issue:

<img width="1450" alt="image"
src="https://github.com/dagster-io/dagster/assets/29110579/3916e1ed-5660-462b-a730-e352461e68b6">

I also went through the UI and confirmed that all other pages were
displaying correctly, so looks like this is the only spot where we
assume partitioned asset(s) are targeted by the backfill.
  • Loading branch information
clairelin135 authored Nov 29, 2023
1 parent 822d653 commit 8fb6b7f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const TargetPartitionsDisplay = ({
targetPartitions,
}: {
targetPartitionCount?: number;
targetPartitions?: Pick<AssetBackfillTargetPartitions, 'partitionKeys' | 'ranges'>;
targetPartitions?: Pick<AssetBackfillTargetPartitions, 'partitionKeys' | 'ranges'> | null;
}) => {
const [isDialogOpen, setIsDialogOpen] = React.useState(false);

Expand Down Expand Up @@ -95,6 +95,12 @@ export const TargetPartitionsDisplay = ({
}

return (
<div>{targetPartitionCount === 1 ? '1 partition' : `${targetPartitionCount} partitions`}</div>
<div>
{targetPartitionCount === 0
? '-'
: targetPartitionCount === 1
? '1 partition'
: `${targetPartitionCount} partitions`}
</div>
);
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Meta:
assetBackfillStatuses = non_null_list(
"dagster_graphql.schema.partition_sets.GrapheneAssetBackfillStatus"
)
rootTargetedPartitions = graphene.NonNull(
rootTargetedPartitions = graphene.Field(
"dagster_graphql.schema.backfill.GrapheneAssetBackfillTargetPartitions",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,49 @@ def test_launch_asset_backfill_with_upstream_anchor_asset_and_non_partitioned_as
assert targeted_ranges[0]["end"] == "2020-01-03-00:00"


def test_asset_backfill_status_only_unpartitioned_assets():
repo = get_daily_hourly_non_partitioned_repo()

with instance_for_test() as instance:
with define_out_of_process_context(
__file__, "get_daily_hourly_non_partitioned_repo", instance
) as context:
# launchPartitionBackfill
launch_backfill_result = execute_dagster_graphql(
context,
LAUNCH_PARTITION_BACKFILL_MUTATION,
variables={
"backfillParams": {
"allPartitions": True,
"assetSelection": [AssetKey("non_partitioned").to_graphql_input()],
}
},
)
backfill_id, asset_backfill_data = _get_backfill_data(
launch_backfill_result, instance, repo
)
target_subset = asset_backfill_data.target_subset

assert target_subset == AssetGraphSubset(
non_partitioned_asset_keys={AssetKey("non_partitioned")},
)

asset_backfill_data_result = execute_dagster_graphql(
context, ASSET_BACKFILL_DATA_QUERY, variables={"backfillId": backfill_id}
)
assert asset_backfill_data_result.data
assert (
asset_backfill_data_result.data["partitionBackfillOrError"]["isAssetBackfill"]
is True
)
assert (
asset_backfill_data_result.data["partitionBackfillOrError"]["assetBackfillData"][
"rootTargetedPartitions"
]
is None
)


def test_asset_backfill_preview_time_partitioned():
repo = get_daily_hourly_non_partitioned_repo()
all_asset_keys = repo.asset_graph.materializable_asset_keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ def get_target_partitions_subset(self, asset_key: AssetKey) -> PartitionsSubset:
# Return the targeted partitions for the root partitioned asset keys
return self.target_subset.get_partitions_subset(asset_key)

def get_target_root_partitions_subset(self, asset_graph: AssetGraph) -> PartitionsSubset:
def get_target_root_partitions_subset(
self, asset_graph: AssetGraph
) -> Optional[PartitionsSubset]:
"""Returns the most upstream partitions subset that was targeted by the backfill."""
partitioned_asset_keys = {
asset_key
Expand All @@ -280,7 +282,10 @@ def get_target_root_partitions_subset(self, asset_graph: AssetGraph) -> Partitio
)

# Return the targeted partitions for the root partitioned asset keys
return self.target_subset.get_partitions_subset(next(iter(root_partitioned_asset_keys)))
if root_partitioned_asset_keys:
return self.target_subset.get_partitions_subset(next(iter(root_partitioned_asset_keys)))

return None

def get_num_partitions(self) -> Optional[int]:
"""Only valid when the same number of partitions are targeted in every asset.
Expand Down

1 comment on commit 8fb6b7f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for dagit-core-storybook ready!

✅ Preview
https://dagit-core-storybook-806xqfvw5-elementl.vercel.app

Built with commit 8fb6b7f.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.