Skip to content

Commit b3562c2

Browse files
authored
[freshness] rename freshness_policy property, arg name to legacy_freshness_policy (dagster-io#30771)
## Summary & Motivation Allows us to use `freshness_policy` as the property or argument name for the new `FreshnessPolicy`. ## How I Tested These Changes unit tests ## Changelog > Insert changelog entry or delete this section.
1 parent 11296d9 commit b3562c2

File tree

48 files changed

+296
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+296
-245
lines changed

examples/starlift-demo/dbt_example/dagster_defs/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def with_deps(
9898
group_names_by_key=assets_def.group_names_by_key,
9999
metadata_by_key=assets_def.metadata_by_key,
100100
tags_by_key=assets_def.tags_by_key,
101-
freshness_policies_by_key=assets_def.freshness_policies_by_key,
101+
legacy_freshness_policies_by_key=assets_def.legacy_freshness_policies_by_key,
102102
backfill_policy=assets_def.backfill_policy,
103103
descriptions_by_key=assets_def.descriptions_by_key,
104104
check_specs_by_output_name=assets_def.check_specs_by_output_name,

python_modules/dagster-graphql/dagster_graphql/schema/asset_graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ def resolve_dependencies(self, graphene_info: ResolveInfo) -> Sequence[GrapheneA
833833
def resolve_freshnessInfo(
834834
self, graphene_info: ResolveInfo
835835
) -> Optional[GrapheneAssetFreshnessInfo]:
836-
if self._asset_node_snap.freshness_policy:
836+
if self._asset_node_snap.legacy_freshness_policy:
837837
return get_freshness_info(
838838
asset_key=self._asset_node_snap.asset_key,
839839
data_time_resolver=graphene_info.context.data_time_resolver,
@@ -843,8 +843,8 @@ def resolve_freshnessInfo(
843843
def resolve_freshnessPolicy(
844844
self, _graphene_info: ResolveInfo
845845
) -> Optional[GrapheneFreshnessPolicy]:
846-
if self._asset_node_snap.freshness_policy:
847-
return GrapheneFreshnessPolicy(self._asset_node_snap.freshness_policy)
846+
if self._asset_node_snap.legacy_freshness_policy:
847+
return GrapheneFreshnessPolicy(self._asset_node_snap.legacy_freshness_policy)
848848
return None
849849

850850
def resolve_internalFreshnessPolicy(

python_modules/dagster-graphql/dagster_graphql_tests/graphql/repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ def fresh_diamond_right(fresh_diamond_top):
18321832

18331833

18341834
@asset(
1835-
freshness_policy=LegacyFreshnessPolicy(maximum_lag_minutes=30),
1835+
legacy_freshness_policy=LegacyFreshnessPolicy(maximum_lag_minutes=30),
18361836
auto_materialize_policy=AutoMaterializePolicy.lazy(),
18371837
)
18381838
def fresh_diamond_bottom(fresh_diamond_left, fresh_diamond_right):

python_modules/dagster-graphql/dagster_graphql_tests/graphql/test_freshness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"""
3030

3131

32-
@observable_source_asset(freshness_policy=LegacyFreshnessPolicy(maximum_lag_minutes=30))
32+
@observable_source_asset(legacy_freshness_policy=LegacyFreshnessPolicy(maximum_lag_minutes=30))
3333
def source_asset_with_freshness(context):
3434
return ObserveResult(metadata={DATA_TIME_METADATA_KEY: float(context.run.tags["data_time"])})
3535

python_modules/dagster-test/dagster_test/toys/auto_materializing/lazy_repo_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def lazy_downstream_3(lazy_downstream_1):
2525

2626
@asset(
2727
auto_materialize_policy=AutoMaterializePolicy.lazy(),
28-
freshness_policy=LegacyFreshnessPolicy(maximum_lag_minutes=1440),
28+
legacy_freshness_policy=LegacyFreshnessPolicy(maximum_lag_minutes=1440),
2929
)
3030
def lazy_downstream_4(lazy_downstream_2, lazy_downstream_3):
3131
return lazy_downstream_2 + lazy_downstream_3
@@ -52,7 +52,7 @@ def lazy_downstream_3_partitioned(lazy_downstream_1_partitioned):
5252
@asset(
5353
partitions_def=daily_partitions_def,
5454
auto_materialize_policy=AutoMaterializePolicy.lazy(),
55-
freshness_policy=LegacyFreshnessPolicy(maximum_lag_minutes=1440),
55+
legacy_freshness_policy=LegacyFreshnessPolicy(maximum_lag_minutes=1440),
5656
)
5757
def lazy_downstream_4_partitioned(lazy_downstream_2_partitioned, lazy_downstream_3_partitioned):
5858
return lazy_downstream_2_partitioned + lazy_downstream_3_partitioned

python_modules/dagster/dagster/_core/definitions/asset_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def create(
3737
group_names_by_key=None,
3838
metadata_by_key=None,
3939
tags_by_key=None,
40-
freshness_policies_by_key=None,
40+
legacy_freshness_policies_by_key=None,
4141
backfill_policy=None,
4242
descriptions_by_key=None,
4343
check_specs_by_output_name=check_specs_by_output_name,

python_modules/dagster/dagster/_core/definitions/asset_graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def partition_mappings(self) -> Mapping[AssetKey, PartitionMapping]: # pyright:
113113
return self._spec.partition_mappings
114114

115115
@property
116-
def freshness_policy(self) -> Optional[LegacyFreshnessPolicy]:
117-
return self._spec.freshness_policy
116+
def legacy_freshness_policy(self) -> Optional[LegacyFreshnessPolicy]:
117+
return self._spec.legacy_freshness_policy
118118

119119
@property
120120
def auto_materialize_policy(self) -> Optional[AutoMaterializePolicy]:

python_modules/dagster/dagster/_core/definitions/asset_out.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
from typing import Any, Optional, Union
33

44
import dagster._check as check
5-
from dagster._annotations import hidden_param, only_allow_hidden_params_in_kwargs, public
5+
from dagster._annotations import (
6+
deprecated_param,
7+
hidden_param,
8+
only_allow_hidden_params_in_kwargs,
9+
public,
10+
)
611
from dagster._core.definitions.asset_dep import AssetDep
712
from dagster._core.definitions.asset_spec import AssetSpec
813
from dagster._core.definitions.auto_materialize_policy import AutoMaterializePolicy
@@ -31,11 +36,7 @@
3136
EMPTY_ASSET_KEY_SENTINEL = AssetKey([])
3237

3338

34-
@hidden_param(
35-
param="freshness_policy",
36-
breaking_version="1.10.0",
37-
additional_warn_text="use freshness checks instead",
38-
)
39+
@deprecated_param(param="legacy_freshness_policy", breaking_version="1.12.0")
3940
@hidden_param(
4041
param="auto_materialize_policy",
4142
breaking_version="1.10.0",
@@ -65,8 +66,6 @@ class AssetOut:
6566
group_name (Optional[str]): A string name used to organize multiple assets into groups. If
6667
not provided, the name "default" is used.
6768
code_version (Optional[str]): The version of the code that generates this asset.
68-
freshness_policy (Optional[FreshnessPolicy]): (Deprecated) A policy which indicates how up
69-
to date this asset is intended to be.
7069
automation_condition (Optional[AutomationCondition]): AutomationCondition to apply to the
7170
specified asset.
7271
backfill_policy (Optional[BackfillPolicy]): BackfillPolicy to apply to the specified asset.
@@ -102,6 +101,7 @@ def __init__(
102101
owners: Optional[Sequence[str]] = None,
103102
tags: Optional[Mapping[str, str]] = None,
104103
kinds: Optional[set[str]] = None,
104+
legacy_freshness_policy: Optional[LegacyFreshnessPolicy] = None,
105105
**kwargs,
106106
):
107107
# Accept a hidden "spec" argument to allow for the AssetOut to be constructed from an AssetSpec
@@ -119,7 +119,6 @@ def __init__(
119119
)
120120

121121
auto_materialize_policy = kwargs.get("auto_materialize_policy")
122-
freshness_policy = kwargs.get("freshness_policy")
123122
has_any_spec_args = any(
124123
[
125124
key,
@@ -129,7 +128,7 @@ def __init__(
129128
code_version,
130129
automation_condition,
131130
auto_materialize_policy,
132-
freshness_policy,
131+
legacy_freshness_policy,
133132
owners,
134133
tags,
135134
kinds,
@@ -156,8 +155,10 @@ def __init__(
156155
"automation_condition",
157156
AutomationCondition,
158157
),
159-
freshness_policy=check.opt_inst_param(
160-
freshness_policy, "freshness_policy", LegacyFreshnessPolicy
158+
legacy_freshness_policy=check.opt_inst_param(
159+
legacy_freshness_policy,
160+
"legacy_freshness_policy",
161+
LegacyFreshnessPolicy,
161162
),
162163
owners=check.opt_sequence_param(owners, "owners", of_type=str),
163164
tags=normalize_tags(tags or {}, strict=True),
@@ -190,8 +191,8 @@ def code_version(self) -> Optional[str]:
190191
return self._spec.code_version
191192

192193
@property
193-
def freshness_policy(self) -> Optional[LegacyFreshnessPolicy]:
194-
return self._spec.freshness_policy
194+
def legacy_freshness_policy(self) -> Optional[LegacyFreshnessPolicy]:
195+
return self._spec.legacy_freshness_policy
195196

196197
@property
197198
def automation_condition(self) -> Optional[AutomationCondition]:

python_modules/dagster/dagster/_core/definitions/asset_spec.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def validate_kind_tags(kinds: Optional[AbstractSet[str]]) -> None:
104104

105105

106106
@hidden_param(
107-
param="freshness_policy",
108-
breaking_version="1.10.0",
109-
additional_warn_text="use freshness checks instead.",
107+
param="legacy_freshness_policy",
108+
breaking_version="1.12.0",
109+
additional_warn_text="use the freshness policy abstraction instead.",
110110
)
111111
@hidden_param(
112112
param="auto_materialize_policy",
@@ -161,7 +161,7 @@ class AssetSpec(IHasInternalInit, IHaveNew, LegacyNamedTupleMixin):
161161
group_name: PublicAttr[Optional[str]]
162162
skippable: PublicAttr[bool]
163163
code_version: PublicAttr[Optional[str]]
164-
freshness_policy: PublicAttr[Optional[LegacyFreshnessPolicy]]
164+
legacy_freshness_policy: PublicAttr[Optional[LegacyFreshnessPolicy]]
165165
automation_condition: PublicAttr[Optional[AutomationCondition]]
166166
owners: PublicAttr[Sequence[str]]
167167
tags: PublicAttr[Mapping[str, str]]
@@ -225,9 +225,9 @@ def __new__(
225225
skippable=check.bool_param(skippable, "skippable"),
226226
group_name=check.opt_str_param(group_name, "group_name"),
227227
code_version=check.opt_str_param(code_version, "code_version"),
228-
freshness_policy=check.opt_inst_param(
229-
kwargs.get("freshness_policy"),
230-
"freshness_policy",
228+
legacy_freshness_policy=check.opt_inst_param(
229+
kwargs.get("legacy_freshness_policy"),
230+
"legacy_freshness_policy",
231231
LegacyFreshnessPolicy,
232232
),
233233
automation_condition=check.opt_inst_param(
@@ -270,7 +270,7 @@ def dagster_internal_init(
270270
skippable=skippable,
271271
group_name=group_name,
272272
code_version=code_version,
273-
freshness_policy=kwargs.get("freshness_policy"),
273+
legacy_freshness_policy=kwargs.get("legacy_freshness_policy"),
274274
automation_condition=automation_condition,
275275
owners=owners,
276276
tags=tags,
@@ -330,7 +330,7 @@ def replace_attributes(
330330
tags: Optional[Mapping[str, str]] = ...,
331331
kinds: Optional[set[str]] = ...,
332332
partitions_def: Optional[PartitionsDefinition] = ...,
333-
freshness_policy: Optional[LegacyFreshnessPolicy] = ...,
333+
legacy_freshness_policy: Optional[LegacyFreshnessPolicy] = ...,
334334
) -> "AssetSpec":
335335
"""Returns a new AssetSpec with the specified attributes replaced."""
336336
current_tags_without_kinds = {
@@ -347,7 +347,7 @@ def replace_attributes(
347347
skippable=skippable if skippable is not ... else self.skippable,
348348
group_name=group_name if group_name is not ... else self.group_name,
349349
code_version=code_version if code_version is not ... else self.code_version,
350-
freshness_policy=self.freshness_policy,
350+
legacy_freshness_policy=self.legacy_freshness_policy,
351351
automation_condition=automation_condition
352352
if automation_condition is not ...
353353
else self.automation_condition,
@@ -396,7 +396,7 @@ def merge_attributes(
396396
skippable=self.skippable,
397397
group_name=self.group_name,
398398
code_version=self.code_version,
399-
freshness_policy=self.freshness_policy,
399+
legacy_freshness_policy=self.legacy_freshness_policy,
400400
automation_condition=self.automation_condition,
401401
owners=[*self.owners, *(owners if owners is not ... else [])],
402402
tags={**current_tags_without_kinds, **(tags if tags is not ... else {})},

0 commit comments

Comments
 (0)