Skip to content

Commit 6d56e42

Browse files
committed
[fix] Fixed source tag translations
1 parent ca6713c commit 6d56e42

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

pyatlan/client/asset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,10 @@ def save(
640640
asset.validate_required()
641641
request = BulkRequest[Asset](entities=entities)
642642
raw_json = self._client._call_api(BULK_UPDATE, query_params, request)
643-
response = AssetMutationResponse(**raw_json)
643+
translated_raw_json = AtlanResponse(
644+
raw_json=raw_json, client=self._client
645+
).to_dict()
646+
response = AssetMutationResponse(**translated_raw_json)
644647
if connections_created := response.assets_created(Connection):
645648
self._wait_for_connections_to_be_created(connections_created)
646649
return response

pyatlan/model/core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import TYPE_CHECKING
88

99
import yaml # type: ignore[import-untyped]
10-
from pydantic.v1 import BaseModel, Extra, Field, PrivateAttr, root_validator, validator
10+
from pydantic.v1 import BaseModel, Extra, Field, root_validator, validator
1111

1212
from pyatlan.model.utils import encoders, to_camel_case
1313

@@ -280,15 +280,15 @@ class Config:
280280
alias="restrictPropagationThroughHierarchy",
281281
)
282282
validity_periods: Optional[List[str]] = Field(default=None, alias="validityPeriods")
283-
_source_tag_attachements: List[SourceTagAttachment] = PrivateAttr(
284-
default_factory=list
283+
source_tag_attachements: List[SourceTagAttachment] = Field(
284+
default_factory=list, exclude=True
285285
)
286286

287287
attributes: Optional[Dict[str, Any]] = None
288288

289-
@property
290-
def source_tag_attachements(self) -> List[SourceTagAttachment]:
291-
return self._source_tag_attachements
289+
# @property
290+
# def source_tag_attachements(self) -> List[SourceTagAttachment]:
291+
# return self._source_tag_attachements
292292

293293
# @validator("type_name", pre=True)
294294
# def type_name_is_tag_name(cls, value):
@@ -340,7 +340,7 @@ def of(
340340
or ""
341341
)
342342
tag.attributes = {source_tag_attr_id: [source_tag_attachment]}
343-
tag._source_tag_attachements.append(source_tag_attachment)
343+
tag.source_tag_attachements.append(source_tag_attachment)
344344
return tag
345345

346346

pyatlan/model/translators.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from abc import ABC, abstractmethod
44
from typing import TYPE_CHECKING, Any, Dict
55

6+
from pyatlan.model.structs import SourceTagAttachment
7+
68
if TYPE_CHECKING:
79
from pyatlan.client.atlan import AtlanClient
810

@@ -41,8 +43,22 @@ def translate(self, data: Dict[str, Any]) -> Dict[str, Any]:
4143
for classification in raw_json[self._CLASSIFICATIONS]:
4244
tag_id = classification.get(self._TYPE_NAME)
4345
if tag_id:
44-
classification[self._TYPE_NAME] = (
45-
self.client.atlan_tag_cache.get_name_for_id(tag_id)
46+
tag_name = self.client.atlan_tag_cache.get_name_for_id(tag_id)
47+
if not tag_name:
48+
return
49+
classification[self._TYPE_NAME] = tag_name
50+
# Check if the tag is a source tag (in that case tag has "attributes")
51+
attr_id = self.client.atlan_tag_cache.get_source_tags_attr_id(
52+
tag_id
4653
)
54+
if attr_id:
55+
classification["source_tag_attachements"] = [
56+
SourceTagAttachment(**source_tag["attributes"])
57+
for source_tag in classification.get("attributes").get(
58+
attr_id
59+
)
60+
if isinstance(source_tag, dict)
61+
and source_tag.get("attributes")
62+
]
4763

4864
return raw_json

tests/unit/test_translators.py

Whitespace-only changes.

0 commit comments

Comments
 (0)