Skip to content

Commit 0fefc5c

Browse files
authored
Merge pull request #635 from atlanhq/APP-6703
APP-6703: Move translation logic out of pydantic validators
2 parents 6723752 + f6a4ae5 commit 0fefc5c

File tree

91 files changed

+1308
-1250
lines changed

Some content is hidden

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

91 files changed

+1308
-1250
lines changed

pyatlan/cache/source_tag_cache.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def get_name(self, asset: Asset):
154154
if not isinstance(asset, Asset):
155155
return
156156
try:
157-
source_tag_name = str(SourceTagName(asset))
157+
source_tag_name = str(SourceTagName(client=self.client, tag=asset))
158158
except AtlanError as e:
159159
LOGGER.error(
160160
"Unable to construct a source tag name for: %s", asset.qualified_name
@@ -174,24 +174,18 @@ class SourceTagName(AbstractAssetName):
174174
_TYPE_NAME = "SourceTagAttachment"
175175
_CONNECTION_DELIMITER = "@@"
176176

177-
def __init__(self, tag: Union[str, Asset]):
177+
def __init__(self, client: AtlanClient, tag: Union[str, Asset]):
178178
self.connection = None
179179
self.partial_tag_name = None
180180

181181
# NOTE: Checking if the first result is an "Asset" since in pyatlan,
182182
# "DbtTag" extends "Dbt" (unlike other tags like "SnowflakeTag" that extend the "Tag" model),
183183
# preventing Dbt tags from being excluded from caching:
184184
if isinstance(tag, Asset):
185-
from pyatlan.client.atlan import AtlanClient
186-
187185
source_tag_qn = tag.qualified_name or ""
188186
tokens = source_tag_qn.split("/")
189187
connection_qn = "/".join(tokens[:3]) if len(tokens) >= 3 else ""
190-
conn = (
191-
AtlanClient.get_current_client().connection_cache.get_by_qualified_name(
192-
connection_qn
193-
)
194-
)
188+
conn = client.connection_cache.get_by_qualified_name(connection_qn)
195189
self.connection = ConnectionName(conn)
196190
self.partial_tag_name = source_tag_qn[len(connection_qn) + 1 :] # noqa
197191

pyatlan/client/asset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ def save(
628628
entities.append(entity)
629629
for asset in entities:
630630
asset.validate_required()
631+
asset.flush_custom_metadata(client=self._client) # type: ignore[arg-type]
631632
request = BulkRequest[Asset](entities=entities)
632633
raw_json = self._client._call_api(BULK_UPDATE, query_params, request)
633634
response = AssetMutationResponse(**raw_json)
@@ -745,6 +746,7 @@ def save_replacing_cm(
745746
entities.append(entity)
746747
for asset in entities:
747748
asset.validate_required()
749+
asset.flush_custom_metadata(client=self._client) # type: ignore[arg-type]
748750
request = BulkRequest[Asset](entities=entities)
749751
raw_json = self._client._call_api(BULK_UPDATE, query_params, request)
750752
return AssetMutationResponse(**raw_json)
@@ -885,6 +887,7 @@ def _restore_asset(self, asset: Asset) -> AssetMutationResponse:
885887
"replaceBusinessAttributes": False,
886888
"overwriteBusinessAttributes": False,
887889
}
890+
to_restore.flush_custom_metadata(self._client) # type: ignore[arg-type]
888891
request = BulkRequest[Asset](entities=[to_restore])
889892
raw_json = self._client._call_api(BULK_UPDATE, query_params, request)
890893
return AssetMutationResponse(**raw_json)
@@ -919,7 +922,7 @@ def _modify_tags(
919922
)
920923

921924
atlan_tag = [
922-
AtlanTag(
925+
AtlanTag( # type: ignore[call-arg]
923926
type_name=AtlanTagName(display_text=name),
924927
propagate=propagate,
925928
remove_propagations_on_entity_delete=remove_propagation_on_delete,
@@ -1091,6 +1094,7 @@ def _update_asset_by_attribute(
10911094
self, asset: A, asset_type: Type[A], qualified_name: str
10921095
):
10931096
query_params = {"attr:qualifiedName": qualified_name}
1097+
asset.flush_custom_metadata(client=self._client) # type: ignore[arg-type]
10941098
raw_json = self._client._call_api(
10951099
PARTIAL_UPDATE_ENTITY_BY_ATTRIBUTE.format_path_with_params(
10961100
asset_type.__name__
@@ -1404,7 +1408,7 @@ def remove_custom_metadata(self, guid: str, cm_name: str):
14041408
:param cm_name: human-readable name of the custom metadata to remove
14051409
:raises AtlanError: on any API communication issue
14061410
"""
1407-
custom_metadata = CustomMetadataDict(name=cm_name)
1411+
custom_metadata = CustomMetadataDict(client=self._client, name=cm_name) # type: ignore[arg-type]
14081412
# invoke clear_all so all attributes are set to None and consequently removed
14091413
custom_metadata.clear_all()
14101414
custom_metadata_request = CustomMetadataRequest.create(

0 commit comments

Comments
 (0)