2222
2323from pydantic .v1 .generics import GenericModel
2424
25+ from pyatlan .errors import ErrorCode
2526from pyatlan .model .constants import DELETED_ , DELETED_SENTINEL
2627from pyatlan .model .enums import AnnouncementType , EntityStatus , SaveSemantic
2728from pyatlan .model .retranslators import AtlanTagRetranslator
@@ -51,11 +52,11 @@ def __init__(self, display_text: str):
5152 # ):
5253 # raise ValueError(f"{display_text} is not a valid Classification")
5354 self ._display_text = display_text
54- self ._id = id
55+ # self._id = id
5556
56- @property
57- def id (self ):
58- return self ._id
57+ # @property
58+ # def id(self):
59+ # return self._id
5960
6061 @classmethod
6162 def get_deleted_sentinel (cls ) -> "AtlanTagName" :
@@ -319,17 +320,12 @@ class Config:
319320 )
320321
321322 attributes : Optional [Dict [str , Any ]] = None
323+ tag_id : Optional [str ] = Field (default = True , exclude = True )
322324
323325 # @property
324326 # def source_tag_attachements(self) -> List[SourceTagAttachment]:
325327 # return self._source_tag_attachements
326328
327- # @validator("type_name", pre=True)
328- # def type_name_is_tag_name(cls, value):
329- # if isinstance(value, AtlanTagName):
330- # return value
331- # return AtlanTagName._convert_to_display_text(value)
332-
333329 # def __init__(self, *args, **kwargs):
334330 # from pyatlan.client.atlan import AtlanClient
335331
@@ -351,27 +347,28 @@ def of(
351347 atlan_tag_name : AtlanTagName ,
352348 entity_guid : Optional [str ] = None ,
353349 source_tag_attachment : Optional [SourceTagAttachment ] = None ,
350+ client : Optional [AtlanClient ] = None ,
354351 ) -> AtlanTag :
355- from pyatlan .client .atlan import AtlanClient
356-
357352 """
358353 Construct an Atlan tag assignment for a specific entity.
359354
360355 :param atlan_tag_name: human-readable name of the Atlan tag
361356 :param entity_guid: unique identifier (GUID) of the entity to which the Atlan tag is to be assigned
362357 :param source_tag_attachment: (optional) source-specific details for the tag
358+ :param client: (optional) client instance used for translating source-specific details
363359 :return: an Atlan tag assignment with default settings for propagation and a specific entity assignment
360+ :raises InvalidRequestError: if client is not provided and source_tag_attachment is specified
364361 """
365362 tag = AtlanTag (type_name = atlan_tag_name )
366363 if entity_guid :
367364 tag .entity_guid = entity_guid
368365 tag .entity_status = EntityStatus .ACTIVE
369366 if source_tag_attachment :
367+ if not client :
368+ raise ErrorCode .NO_ATLAN_CLIENT .exception_with_parameters ()
369+ tag_id = client .atlan_tag_cache .get_id_for_name (str (atlan_tag_name ))
370370 source_tag_attr_id = (
371- AtlanClient .get_current_client ().atlan_tag_cache .get_source_tags_attr_id (
372- atlan_tag_name .id
373- )
374- or ""
371+ client .atlan_tag_cache .get_source_tags_attr_id (tag_id ) or ""
375372 )
376373 tag .attributes = {source_tag_attr_id : [source_tag_attachment ]}
377374 tag .source_tag_attachements .append (source_tag_attachment )
0 commit comments