Skip to content

Commit d2a457d

Browse files
authored
[ML] Fix auto delete setting comparison bug in Asset (Azure#30232)
* Fix comparison bug * Add a ut
1 parent 17f950a commit d2a457d

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_assets/asset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __eq__(self, other) -> bool:
120120
and self.base_path == other.base_path
121121
and self._is_anonymous == other._is_anonymous
122122
and self._auto_increment_version == other._auto_increment_version
123-
and self.auto_delete_setting == other._auto_delete_setting
123+
and self.auto_delete_setting == other.auto_delete_setting
124124
)
125125

126126
def __ne__(self, other) -> bool:

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_assets/auto_delete_setting.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
44

5-
from typing import Any
5+
from typing import Any, Union
66
from azure.ai.ml._utils._experimental import experimental
77
from azure.ai.ml.constants._common import AutoDeleteCondition
88
from azure.ai.ml.entities._mixins import DictMixin
@@ -19,7 +19,12 @@ class AutoDeleteSetting(DictMixin):
1919
:type value: str
2020
"""
2121

22-
def __init__(self, *, condition: AutoDeleteCondition = AutoDeleteCondition.CREATED_GREATER_THAN, value: str = None):
22+
def __init__(
23+
self,
24+
*,
25+
condition: AutoDeleteCondition = AutoDeleteCondition.CREATED_GREATER_THAN,
26+
value: Union[str, None] = None
27+
):
2328
self.condition = condition
2429
self.value = value
2530

sdk/ml/azure-ai-ml/tests/dataset/unittests/test_data_schema.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from azure.ai.ml import load_data
99
from azure.ai.ml.entities._assets import Data
10+
from azure.ai.ml.entities._assets.asset import Asset
11+
from azure.ai.ml.entities._assets.auto_delete_setting import AutoDeleteSetting, AutoDeleteCondition
1012

1113

1214
@pytest.mark.unittest
@@ -59,3 +61,37 @@ def test_deserialize_empty_paths_should_get_validation_error(self):
5961
with pytest.raises(ValidationError) as e:
6062
load_data(source=test_path)
6163
assert "Missing data for required field" in e.value.messages[0]
64+
65+
def test_asset_eq(self):
66+
auto_delete_setting = AutoDeleteSetting(condition=AutoDeleteCondition.CREATED_GREATER_THAN, value="30d")
67+
# with auto delete setting
68+
targetAsset = Data(
69+
name="testDataAssetfolder",
70+
version="1",
71+
description="this is a test data asset with auto delete setting",
72+
path="azureml://datastores/workspacemanageddatastore/",
73+
auto_delete_setting=auto_delete_setting,
74+
)
75+
test_path = "./tests/test_configs/dataset/data_with_auto_delete_setting.yml"
76+
with open(test_path, "r") as f:
77+
asset: Data = load_data(source=test_path)
78+
79+
# the path types are different in load_data and raw Data
80+
targetAsset._base_path = asset.base_path
81+
assert Asset.__eq__(asset, targetAsset) is True
82+
83+
# without auto delete setting
84+
targetAsset = Data(
85+
name="testDataAssetfolder",
86+
version="1",
87+
description="this is a test data asset without auto delete setting",
88+
path="azureml://datastores/workspacemanageddatastore/",
89+
auto_delete_setting=auto_delete_setting,
90+
)
91+
test_path = "./tests/test_configs/dataset/data_without_auto_delete_setting.yml"
92+
with open(test_path, "r") as f:
93+
asset: Data = load_data(source=test_path)
94+
95+
# the path types are different in load_data and raw Data
96+
targetAsset._base_path = asset.base_path
97+
assert Asset.__eq__(asset, targetAsset) is False
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: testDataAssetfolder
2+
version: 1
3+
description: "this is a test data asset with auto delete setting"
4+
path: azureml://datastores/workspacemanageddatastore/
5+
6+
auto_delete_setting:
7+
condition: created_greater_than
8+
value: 30d
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: testDataAssetfolder
2+
version: 1
3+
description: "this is a test data asset without auto delete setting"
4+
path: azureml://datastores/workspacemanageddatastore/

0 commit comments

Comments
 (0)