Skip to content

Commit fc6f221

Browse files
committed
Refactored BusinessAttributes to CustomeMetadata
1 parent 841cdf1 commit fc6f221

6 files changed

Lines changed: 44 additions & 44 deletions

File tree

pyatlan/cache/custom_metadata_cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from pyatlan.client.atlan import AtlanClient
77
from pyatlan.error import LogicError, NotFoundError
8-
from pyatlan.model.core import BusinessAttributes
8+
from pyatlan.model.core import CustomMetadata
99
from pyatlan.model.enums import AtlanTypeCategory
1010
from pyatlan.model.typedef import AttributeDef, CustomMetadataDef
1111

@@ -36,7 +36,7 @@ class CustomMetadataCache:
3636

3737
@classmethod
3838
def _refresh_cache(cls) -> None:
39-
from pyatlan.model.core import BusinessAttributes, to_snake_case
39+
from pyatlan.model.core import CustomMetadata, to_snake_case
4040

4141
client = AtlanClient.get_default_client()
4242
if client is None:
@@ -59,7 +59,7 @@ def _refresh_cache(cls) -> None:
5959
cls.map_attr_name_to_id[type_id] = {}
6060
meta_name = cm.display_name.replace(" ", "")
6161
attribute_class_name = f"Attributes_{meta_name}"
62-
attrib_type = type(attribute_class_name, (BusinessAttributes,), {})
62+
attrib_type = type(attribute_class_name, (CustomMetadata,), {})
6363
attrib_type._meta_data_type_id = type_id # type: ignore
6464
attrib_type._meta_data_type_name = type_name # type: ignore
6565
cls.map_id_to_type[type_id] = attrib_type
@@ -210,7 +210,7 @@ def get_custom_metadata(
210210
name: str,
211211
asset_type: type,
212212
business_attributes: Optional[dict[str, Any]] = None,
213-
) -> BusinessAttributes:
213+
) -> CustomMetadata:
214214
type_name = asset_type.__name__
215215
ba_id = cls.get_id_for_name(name)
216216
if ba_id is None:

pyatlan/generator/templates/entity.jinja2

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from typing import Any, ClassVar, Dict, List, Optional, TypeVar
99

1010
from pydantic import Field, StrictStr, root_validator, validator
1111

12-
from pyatlan.model.core import Announcement, AtlanObject, BusinessAttributes, Classification, Meaning
12+
from pyatlan.model.core import Announcement, AtlanObject, CustomMetadata, Classification, Meaning
1313
from pyatlan.model.enums import (
1414
ADLSAccessTier,
1515
ADLSAccountStatus,
@@ -226,7 +226,7 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
226226
if not self.create_time or self.created_by:
227227
self.attributes.validate_required()
228228

229-
def get_business_attributes(self, name: str) -> BusinessAttributes:
229+
def get_custom_metadata(self, name: str) -> CustomMetadata:
230230
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
231231

232232
ba_id = CustomMetadataCache.get_id_for_name(name)
@@ -240,7 +240,7 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
240240
break
241241
else:
242242
raise ValueError(
243-
f"Business attributes {name} are not applicable to {self.type_name}"
243+
f"Custom metadata attributes {name} are not applicable to {self.type_name}"
244244
)
245245
if ba_type := CustomMetadataCache.get_type_for_id(ba_id):
246246
return (
@@ -250,27 +250,27 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
250250
)
251251
else:
252252
raise ValueError(
253-
f"Business attributes {name} are not applicable to {self.type_name}"
253+
f"Custom metadata attributes {name} are not applicable to {self.type_name}"
254254
)
255255

256-
def set_business_attribute(self, business_attributes: BusinessAttributes) -> None:
256+
def set_custom_metadata(self, custom_metadata: CustomMetadata) -> None:
257257
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
258258

259-
if not isinstance(business_attributes, BusinessAttributes):
259+
if not isinstance(custom_metadata, CustomMetadata):
260260
raise ValueError(
261-
"business_attributes must be an instance of BusinessAttributes"
261+
"business_attributes must be an instance of CustomMetadata"
262262
)
263263
if (
264-
type(business_attributes)
264+
type(custom_metadata)
265265
not in CustomMetadataCache.types_by_asset[self.type_name]
266266
):
267267
raise ValueError(
268-
f"Business attributes {business_attributes._meta_data_type_name} are not applicable to {self.type_name}"
268+
f"Business attributes {custom_metadata._meta_data_type_name} are not applicable to {self.type_name}"
269269
)
270-
ba_dict = dict(business_attributes)
270+
ba_dict = dict(custom_metadata)
271271
if not self.business_attributes:
272272
self.business_attributes = {}
273-
self.business_attributes[business_attributes._meta_data_type_id] = ba_dict
273+
self.business_attributes[custom_metadata._meta_data_type_id] = ba_dict
274274

275275
{%- else %}
276276
{%- if entity_def.name == "Asset" %}

pyatlan/model/assets.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from pyatlan.model.core import (
1313
Announcement,
1414
AtlanObject,
15-
BusinessAttributes,
1615
Classification,
16+
CustomMetadata,
1717
Meaning,
1818
)
1919
from pyatlan.model.enums import (
@@ -246,12 +246,12 @@ def validate_required(self):
246246
if not self.create_time or self.created_by:
247247
self.attributes.validate_required()
248248

249-
def get_business_attributes(self, name: str) -> BusinessAttributes:
249+
def get_custom_metadata(self, name: str) -> CustomMetadata:
250250
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
251251

252252
ba_id = CustomMetadataCache.get_id_for_name(name)
253253
if ba_id is None:
254-
raise ValueError(f"No business attributes with the name: {name} exist")
254+
raise ValueError(f"No custom metadata with the name: {name} exist")
255255
for a_type in CustomMetadataCache.types_by_asset[self.type_name]:
256256
if (
257257
hasattr(a_type, "_meta_data_type_name")
@@ -260,7 +260,7 @@ def get_business_attributes(self, name: str) -> BusinessAttributes:
260260
break
261261
else:
262262
raise ValueError(
263-
f"Business attributes {name} are not applicable to {self.type_name}"
263+
f"Custom metadata attributes {name} are not applicable to {self.type_name}"
264264
)
265265
if ba_type := CustomMetadataCache.get_type_for_id(ba_id):
266266
return (
@@ -270,27 +270,27 @@ def get_business_attributes(self, name: str) -> BusinessAttributes:
270270
)
271271
else:
272272
raise ValueError(
273-
f"Business attributes {name} are not applicable to {self.type_name}"
273+
f"Custom metadata attributes {name} are not applicable to {self.type_name}"
274274
)
275275

276-
def set_business_attribute(self, business_attributes: BusinessAttributes) -> None:
276+
def set_custom_metadata(self, custom_metadata: CustomMetadata) -> None:
277277
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
278278

279-
if not isinstance(business_attributes, BusinessAttributes):
279+
if not isinstance(custom_metadata, CustomMetadata):
280280
raise ValueError(
281-
"business_attributes must be an instance of BusinessAttributes"
281+
"business_attributes must be an instance of CustomMetadata"
282282
)
283283
if (
284-
type(business_attributes)
284+
type(custom_metadata)
285285
not in CustomMetadataCache.types_by_asset[self.type_name]
286286
):
287287
raise ValueError(
288-
f"Business attributes {business_attributes._meta_data_type_name} are not applicable to {self.type_name}"
288+
f"Business attributes {custom_metadata._meta_data_type_name} are not applicable to {self.type_name}"
289289
)
290-
ba_dict = dict(business_attributes)
290+
ba_dict = dict(custom_metadata)
291291
if not self.business_attributes:
292292
self.business_attributes = {}
293-
self.business_attributes[business_attributes._meta_data_type_id] = ba_dict
293+
self.business_attributes[custom_metadata._meta_data_type_id] = ba_dict
294294

295295

296296
class Asset(Referenceable):

pyatlan/model/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class BulkRequest(AtlanObject, GenericModel, Generic[T]):
189189
entities: list[T]
190190

191191

192-
class BusinessAttributes(dict):
192+
class CustomMetadata(dict):
193193
_meta_data_type_name = ""
194194
_meta_data_type_id = ""
195195

tests/integration/custom_metadata_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_003_purge_custom_metadata(client: AtlanClient):
8787

8888
def test_custom_metadata_has_human_readable_properties(client: AtlanClient):
8989
table = client.get_asset_by_guid("5f47cfb9-1313-4f03-9213-9913fff3c878", Table)
90-
anomalo = table.get_business_attributes("Anomalo")
90+
anomalo = table.get_custom_metadata("Anomalo")
9191
assert hasattr(anomalo, "data_volume")
9292
assert anomalo.data_volume is None
9393
assert hasattr(anomalo, "data_volume_details")
@@ -114,7 +114,7 @@ def test_custom_metadata_has_human_readable_properties(client: AtlanClient):
114114
assert anomalo.validation_rules is None
115115
assert hasattr(anomalo, "validation_rules_details")
116116
assert anomalo.validation_rules_details is None
117-
monte_carlo = table.get_business_attributes("Monte Carlo")
117+
monte_carlo = table.get_custom_metadata("Monte Carlo")
118118
assert monte_carlo is not None
119119

120120

tests/unit/test_model.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,9 +1031,9 @@ def test_get_business_attributes_when_name_not_valid_raises_value_error(
10311031
):
10321032
mock_client.return_value.get_typedefs.return_value = type_def_response
10331033
with pytest.raises(
1034-
ValueError, match="No business attributes with the name: Zoro exist"
1034+
ValueError, match="No custom metadata with the name: Zoro exist"
10351035
):
1036-
table.get_business_attributes("Zoro")
1036+
table.get_custom_metadata("Zoro")
10371037

10381038

10391039
@patch("pyatlan.cache.custom_metadata_cache.AtlanClient")
@@ -1043,9 +1043,9 @@ def test_get_business_attributes_when_name_not_appropriate_for_asset_raises_valu
10431043
mock_client.get_default_client.return_value = mock_client
10441044
mock_client.get_typedefs.return_value = type_def_response
10451045
with pytest.raises(
1046-
ValueError, match="Business attributes Moon are not applicable to Table"
1046+
ValueError, match="Custom metadata attributes Moon are not applicable to Table"
10471047
):
1048-
table.get_business_attributes("Moon")
1048+
table.get_custom_metadata("Moon")
10491049

10501050

10511051
@patch("pyatlan.cache.custom_metadata_cache.AtlanClient")
@@ -1054,7 +1054,7 @@ def test_get_business_attributes_with_valid_name_returns_empty_attribute_when_ta
10541054
):
10551055
mock_client.return_value.get_typedefs.return_value = type_def_response
10561056

1057-
monte_carlo = table.get_business_attributes("Monte Carlo")
1057+
monte_carlo = table.get_custom_metadata("Monte Carlo")
10581058

10591059
assert monte_carlo is not None
10601060
assert monte_carlo.freshness is None
@@ -1074,7 +1074,7 @@ def test_get_business_attributes_with_valid_name_returns_attribute_when_table_ha
10741074
}
10751075
}
10761076

1077-
monte_carlo = table.get_business_attributes("Monte Carlo")
1077+
monte_carlo = table.get_custom_metadata("Monte Carlo")
10781078

10791079
assert monte_carlo is not None
10801080
assert monte_carlo.freshness == "pass"
@@ -1086,9 +1086,9 @@ def test_set_busines_attributes_with_non_business_attributes_object_raises_value
10861086
):
10871087
with pytest.raises(
10881088
ValueError,
1089-
match="business_attributes must be an instance of BusinessAttributes",
1089+
match="business_attributes must be an instance of CustomMetadata",
10901090
):
1091-
table.set_business_attribute({})
1091+
table.set_custom_metadata({})
10921092

10931093

10941094
def test_set_business_attributes_with_non_appropriate_meta_data_type_name_raises_value_error(
@@ -1097,9 +1097,9 @@ def test_set_business_attributes_with_non_appropriate_meta_data_type_name_raises
10971097

10981098
with pytest.raises(
10991099
ValueError,
1100-
match="business_attributes must be an instance of BusinessAttributes",
1100+
match="business_attributes must be an instance of CustomMetadata",
11011101
):
1102-
table.set_business_attribute({})
1102+
table.set_custom_metadata({})
11031103

11041104

11051105
@patch("pyatlan.cache.custom_metadata_cache.AtlanClient")
@@ -1113,7 +1113,7 @@ def test_assigning_to_invalid_business_attribute_raises_attribute_error(
11131113
TABLE_URL: "https://getmontecarlo.com/catalog/",
11141114
}
11151115
}
1116-
business_attributes = table.get_business_attributes("Monte Carlo")
1116+
business_attributes = table.get_custom_metadata("Monte Carlo")
11171117
with pytest.raises(AttributeError, match="Attribute bogus does not exist"):
11181118
business_attributes.bogus = "123"
11191119

@@ -1130,7 +1130,7 @@ def test_set_business_attributes_with_business_attribute_not_appropriate_to_asse
11301130
ValueError,
11311131
match="Business attributes Moon are not applicable to Table",
11321132
):
1133-
table.set_business_attribute(moon)
1133+
table.set_custom_metadata(moon)
11341134

11351135

11361136
@patch("pyatlan.cache.custom_metadata_cache.AtlanClient")
@@ -1145,11 +1145,11 @@ def test_set_business_attributes_with_appropriate_business_attribute_updates_dic
11451145
TABLE_URL: "https://getmontecarlo.com/catalog/",
11461146
}
11471147
}
1148-
monte_carlo = table.get_business_attributes("Monte Carlo")
1148+
monte_carlo = table.get_custom_metadata("Monte Carlo")
11491149

11501150
monte_carlo.freshness = "fail"
11511151
monte_carlo.table_url = "http://anywhere.com"
1152-
table.set_business_attribute(monte_carlo)
1152+
table.set_custom_metadata(monte_carlo)
11531153

11541154
monte_carlo_dict = table.business_attributes[MONTE_CARLO]
11551155
assert monte_carlo_dict[FRESHNESS] == monte_carlo.freshness

0 commit comments

Comments
 (0)