Skip to content

Commit 885649c

Browse files
authored
Merge branch 'main' into FT-585
2 parents 6a577fd + 2219cf4 commit 885649c

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

Diff for: pyatlan/model/core.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _convert_to_display_text(cls, data):
8484
if display_text := AtlanTagCache.get_name_for_id(data):
8585
return AtlanTagName(display_text)
8686
else:
87-
raise ValueError(f"{data} is not a valid AtlanTag")
87+
return cls.get_deleted_sentinel()
8888

8989
@staticmethod
9090
def json_encode_atlan_tag(atlan_tag_name: "AtlanTagName"):
@@ -237,11 +237,7 @@ def source_tag_attachements(self) -> List[SourceTagAttachment]:
237237
def type_name_is_tag_name(cls, value):
238238
if isinstance(value, AtlanTagName):
239239
return value
240-
try:
241-
value = AtlanTagName._convert_to_display_text(value)
242-
except ValueError:
243-
value = AtlanTagName.get_deleted_sentinel()
244-
return value
240+
return AtlanTagName._convert_to_display_text(value)
245241

246242
def __init__(self, *args, **kwargs):
247243
from pyatlan.cache.atlan_tag_cache import AtlanTagCache

Diff for: tests/unit/test_atlan_tag_name.py

+73-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright 2022 Atlan Pte. Ltd.
33
import pytest
4+
from pydantic.v1 import parse_obj_as
45

56
import pyatlan.cache.atlan_tag_cache
7+
from pyatlan.model.assets import Purpose
8+
from pyatlan.model.constants import DELETED_
69
from pyatlan.model.core import AtlanTagName
710

811
ATLAN_TAG_ID = "yiB7RLvdC2yeryLPjaDeHM"
@@ -62,7 +65,7 @@ def test_convert_to_display_text_when_atlan_tag_passed_returns_same_atlan_tag(
6265
assert good_atlan_tag is AtlanTagName._convert_to_display_text(good_atlan_tag)
6366

6467

65-
def test_convert_to_display_text_when_bad_string_raises_value_error(monkeypatch):
68+
def test_convert_to_display_text_when_bad_string(monkeypatch):
6669
def get_name_for_id(_):
6770
return None
6871

@@ -72,8 +75,10 @@ def get_name_for_id(_):
7275
get_name_for_id,
7376
)
7477

75-
with pytest.raises(ValueError, match="bad is not a valid AtlanTag"):
76-
AtlanTagName._convert_to_display_text("bad")
78+
assert (
79+
AtlanTagName._convert_to_display_text("bad").__repr__()
80+
== f"AtlanTagName('{DELETED_}')"
81+
)
7782

7883

7984
def test_convert_to_display_text_when_id(monkeypatch):
@@ -102,3 +107,68 @@ def get_id_for_name(value):
102107

103108
def test_json_encode_atlan_tag(monkeypatch, good_atlan_tag):
104109
assert AtlanTagName.json_encode_atlan_tag(good_atlan_tag) == ATLAN_TAG_ID
110+
111+
112+
def test_asset_tag_name_field_deserialization(monkeypatch):
113+
def get_name_for_id(_):
114+
return None
115+
116+
def get_id_for_name(_):
117+
return None
118+
119+
monkeypatch.setattr(
120+
pyatlan.cache.atlan_tag_cache.AtlanTagCache,
121+
"get_id_for_name",
122+
get_id_for_name,
123+
)
124+
125+
monkeypatch.setattr(
126+
pyatlan.cache.atlan_tag_cache.AtlanTagCache,
127+
"get_name_for_id",
128+
get_name_for_id,
129+
)
130+
# Simulate a `Purpose` asset with `purpose_atlan_tags` of type `AtlanTagName`
131+
purpose_asset = {
132+
"typeName": "Purpose",
133+
"attributes": {
134+
# AtlanTagName
135+
"purposeClassifications": [
136+
"some-deleted-purpose-tag-1",
137+
"some-deleted-purpose-tag-2",
138+
],
139+
},
140+
"guid": "9f7a35f4-8d37-4273-81ec-c497a83a2472",
141+
"status": "ACTIVE",
142+
"classifications": [
143+
# AtlanTag
144+
{
145+
"typeName": "some-deleted-purpose-tag-1",
146+
"entityGuid": "82683fb9-1501-4627-a5d0-0da9be64c0d5",
147+
"entityStatus": "DELETED",
148+
"propagate": False,
149+
"removePropagationsOnEntityDelete": True,
150+
"restrictPropagationThroughLineage": True,
151+
"restrictPropagationThroughHierarchy": False,
152+
},
153+
{
154+
"typeName": "some-deleted-purpose-tag-2",
155+
"entityGuid": "82683fb9-1501-4627-a5d0-0da9be64c0d5",
156+
"entityStatus": "DELETED",
157+
"propagate": False,
158+
"removePropagationsOnEntityDelete": True,
159+
"restrictPropagationThroughLineage": True,
160+
"restrictPropagationThroughHierarchy": False,
161+
},
162+
],
163+
}
164+
purpose = parse_obj_as(Purpose, purpose_asset)
165+
assert purpose and isinstance(purpose, Purpose)
166+
167+
# Verify that deleted tags are correctly set to `None`
168+
# assert purpose.atlan_tags == [AtlanTagName('(DELETED)')]
169+
assert purpose.atlan_tags and len(purpose.atlan_tags) == 2
170+
assert purpose.atlan_tags[0].type_name.__repr__() == f"AtlanTagName('{DELETED_}')"
171+
assert purpose.atlan_tags[1].type_name.__repr__() == f"AtlanTagName('{DELETED_}')"
172+
assert purpose.purpose_atlan_tags and len(purpose.purpose_atlan_tags) == 2
173+
assert purpose.purpose_atlan_tags[0].__repr__() == f"AtlanTagName('{DELETED_}')"
174+
assert purpose.purpose_atlan_tags[1].__repr__() == f"AtlanTagName('{DELETED_}')"

0 commit comments

Comments
 (0)