https://dagster.io/ logo
#ask-ai
Title
# ask-ai
t

TruffleOil

03/08/2024, 1:53 PM
I wish to setup my asset (Asset B) to depend on an earlier partition of an upstream asset (Asset A), in order to comply with the error:
Copy code
"Assets can only depend on themselves if they are:
(a) time-partitioned and each partition depends on earlier partitions"
How can I do that? Show me an example.
s

Scout

03/08/2024, 1:53 PM
To set up your asset (Asset B) to depend on an earlier partition of an upstream asset (Asset A), you can use a
TimeWindowPartitionMapping
to specify that each partition of Asset B should depend on the prior partition of Asset A. Here's an example from the documentation that demonstrates how to do this:
Copy code
python from dagster import (     AssetDep,     DailyPartitionsDefinition,     TimeWindowPartitionMapping,     asset, )  partitions_def = DailyPartitionsDefinition(start_date="2023-01-21")  @asset(partitions_def=partitions_def) def asset_a():     ...  @asset(     partitions_def=partitions_def,     deps=[         AssetDep(             asset_a,             partition_mapping=TimeWindowPartitionMapping(                 start_offset=-1, end_offset=-1             ),         )     ], ) def asset_b():     ...
In this example,
asset_a
is defined with a daily partition starting from a specific date.
asset_b
is defined to depend on
asset_a
, and the
TimeWindowPartitionMapping
is used to specify that each partition of
asset_b
should depend on the prior day's partition of
asset_a
. The
start_offset
and
end_offset
are both set to
-1
, indicating that
asset_b
depends on the partition of
asset_a
from one day earlier.
t

TruffleOil

03/08/2024, 2:49 PM
@Scout I tried implementing the above. asset_a materialized without issue but I'm getting an error when materializing asset_b:
Copy code
dagster._check.CheckError: Failure condition: downstream_partitions_subset must be a BaseTimeWindowPartitionsSubset
What is the issue?
s

Scout

03/08/2024, 2:49 PM
The error message you're encountering,
Failure condition: downstream_partitions_subset must be a BaseTimeWindowPartitionsSubset
, suggests that there is a mismatch between the expected partition subset type and the one being provided during the materialization process of
asset_b
. This error could occur if the partition mapping is not set up correctly or if there is an issue with how the partitions are defined for
asset_b
. The
TimeWindowPartitionMapping
expects that the partitions of both the upstream and downstream assets are defined in a way that is compatible with time window partitioning. To resolve this issue, ensure the following: 1. Both
asset_a
and
asset_b
have compatible partition definitions. If they are using
DailyPartitionsDefinition
, they should both be configured with the same start date and frequency. 2. The
TimeWindowPartitionMapping
is correctly configured with the appropriate offsets to map the partitions from
asset_a
to
asset_b
. 3. When materializing
asset_b
, you are providing a valid partition key that exists within the defined partitions. If you've verified these points and the issue persists, it could be helpful to review the full stack trace of the error and check the partition definitions and materialization logic for any discrepancies. If the problem is not immediately apparent, you may need to provide more context or seek further assistance from the Dagster community or support channels, as the error might be specific to your implementation details or environment.