@@ -64,18 +64,6 @@ def _build_typedef_request(typedef: TypeDef) -> TypeDefResponse:
6464 return payload
6565
6666
67- def _refresh_caches (typedef : TypeDef ) -> None :
68- from pyatlan .client .atlan import AtlanClient
69-
70- client = AtlanClient .get_current_client ()
71- if isinstance (typedef , AtlanTagDef ):
72- client .atlan_tag_cache .refresh_cache ()
73- if isinstance (typedef , CustomMetadataDef ):
74- client .custom_metadata_cache .refresh_cache ()
75- if isinstance (typedef , EnumDef ):
76- client .enum_cache .refresh_cache ()
77-
78-
7967class TypeDefFactory :
8068 @staticmethod
8169 def create (raw_json : dict ) -> TypeDef :
@@ -117,6 +105,14 @@ def __init__(self, client: ApiCaller):
117105 )
118106 self ._client = client
119107
108+ def _refresh_caches (self , typedef : TypeDef ) -> None :
109+ if isinstance (typedef , AtlanTagDef ):
110+ self ._client .atlan_tag_cache .refresh_cache () # type: ignore[attr-defined]
111+ if isinstance (typedef , CustomMetadataDef ):
112+ self ._client .custom_metadata_cache .refresh_cache () # type: ignore[attr-defined]
113+ if isinstance (typedef , EnumDef ):
114+ self ._client .enum_cache .refresh_cache () # type: ignore[attr-defined]
115+
120116 def get_all (self ) -> TypeDefResponse :
121117 """
122118 Retrieves a TypeDefResponse object that contains a list of all the type definitions in Atlan.
@@ -189,7 +185,7 @@ def create(self, typedef: TypeDef) -> TypeDefResponse:
189185 raw_json = self ._client ._call_api (
190186 CREATE_TYPE_DEFS , request_obj = payload , exclude_unset = True
191187 )
192- _refresh_caches (typedef )
188+ self . _refresh_caches (typedef )
193189 return TypeDefResponse (** raw_json )
194190
195191 @validate_arguments
@@ -210,7 +206,7 @@ def update(self, typedef: TypeDef) -> TypeDefResponse:
210206 raw_json = self ._client ._call_api (
211207 UPDATE_TYPE_DEFS , request_obj = payload , exclude_unset = True
212208 )
213- _refresh_caches (typedef )
209+ self . _refresh_caches (typedef )
214210 return TypeDefResponse (** raw_json )
215211
216212 @validate_arguments
@@ -226,29 +222,26 @@ def purge(self, name: str, typedef_type: type) -> None:
226222 :raises NotFoundError: if the typedef you are trying to delete cannot be found
227223 :raises AtlanError: on any API communication issue
228224 """
229- from pyatlan .client .atlan import AtlanClient
230-
231- client = AtlanClient .get_current_client ()
232225 if typedef_type == CustomMetadataDef :
233- internal_name = client . custom_metadata_cache .get_id_for_name (name )
226+ internal_name = self . _client . custom_metadata_cache .get_id_for_name (name ) # type: ignore[attr-defined]
234227 elif typedef_type == EnumDef :
235228 internal_name = name
236229 elif typedef_type == AtlanTagDef :
237- internal_name = str (client . atlan_tag_cache .get_id_for_name (name ))
230+ internal_name = str (self . _client . atlan_tag_cache .get_id_for_name (name )) # type: ignore[attr-defined]
238231 else :
239232 raise ErrorCode .UNABLE_TO_PURGE_TYPEDEF_OF_TYPE .exception_with_parameters (
240233 typedef_type
241234 )
242235 if internal_name :
243- self ._client ._call_api (
236+ self ._client ._client . _call_api ( # type: ignore[attr-defined]
244237 DELETE_TYPE_DEF_BY_NAME .format_path_with_params (internal_name )
245238 )
246239 else :
247240 raise ErrorCode .TYPEDEF_NOT_FOUND_BY_NAME .exception_with_parameters (name )
248241
249242 if typedef_type == CustomMetadataDef :
250- client . custom_metadata_cache .refresh_cache ()
243+ self . _client . custom_metadata_cache .refresh_cache () # type: ignore[attr-defined]
251244 elif typedef_type == EnumDef :
252- client . enum_cache .refresh_cache ()
245+ self . _client . enum_cache .refresh_cache () # type: ignore[attr-defined]
253246 elif typedef_type == AtlanTagDef :
254- client . atlan_tag_cache .refresh_cache ()
247+ self . _client . atlan_tag_cache .refresh_cache () # type: ignore[attr-defined]
0 commit comments