Skip to content

Commit 68e4b77

Browse files
committed
Merge branch 'main' into get_lineage
2 parents c926e4f + e682638 commit 68e4b77

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

pyatlan/cache/classification_cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ClassificationCache:
1515
deleted_names: set[str] = set()
1616

1717
@classmethod
18-
def _refresh_cache(cls) -> None:
18+
def refresh_cache(cls) -> None:
1919
from pyatlan.client.atlan import AtlanClient
2020

2121
client = AtlanClient.get_default_client()
@@ -41,7 +41,7 @@ def get_id_for_name(cls, name: str) -> Optional[str]:
4141
cls_id = cls.map_name_to_id.get(name)
4242
if not cls_id and name not in cls.deleted_names:
4343
# If not found, refresh the cache and look again (could be stale)
44-
cls._refresh_cache()
44+
cls.refresh_cache()
4545
cls_id = cls.map_name_to_id.get(name)
4646
if not cls_id:
4747
# If still not found after refresh, mark it as deleted (could be
@@ -58,7 +58,7 @@ def get_name_for_id(cls, idstr: str) -> Optional[str]:
5858
cls_name = cls.map_id_to_name.get(idstr)
5959
if not cls_name and idstr not in cls.deleted_ids:
6060
# If not found, refresh the cache and look again (could be stale)
61-
cls._refresh_cache()
61+
cls.refresh_cache()
6262
cls_name = cls.map_id_to_name.get(idstr)
6363
if not cls_name:
6464
# If still not found after refresh, mark it as deleted (could be

pyatlan/cache/custom_metadata_cache.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CustomMetadataCache:
3535
types_by_asset: dict[str, set[type]] = dict()
3636

3737
@classmethod
38-
def _refresh_cache(cls) -> None:
38+
def refresh_cache(cls) -> None:
3939
from pyatlan.model.core import CustomMetadata, to_snake_case
4040

4141
client = AtlanClient.get_default_client()
@@ -98,7 +98,7 @@ def get_id_for_name(cls, name: str) -> Optional[str]:
9898
if cm_id := cls.map_name_to_id.get(name):
9999
return cm_id
100100
# If not found, refresh the cache and look again (could be stale)
101-
cls._refresh_cache()
101+
cls.refresh_cache()
102102
return cls.map_name_to_id.get(name)
103103

104104
@classmethod
@@ -109,14 +109,14 @@ def get_name_for_id(cls, idstr: str) -> Optional[str]:
109109
if cm_name := cls.map_id_to_name.get(idstr):
110110
return cm_name
111111
# If not found, refresh the cache and look again (could be stale)
112-
cls._refresh_cache()
112+
cls.refresh_cache()
113113
return cls.map_id_to_name.get(idstr)
114114

115115
@classmethod
116116
def get_type_for_id(cls, idstr: str) -> Optional[type]:
117117
if cm_type := cls.map_id_to_type.get(idstr):
118118
return cm_type
119-
cls._refresh_cache()
119+
cls.refresh_cache()
120120
return cls.map_id_to_type.get(idstr)
121121

122122
@classmethod
@@ -129,7 +129,7 @@ def get_all_custom_attributes(
129129
of each of those attributes).
130130
"""
131131
if len(cls.cache_by_id) == 0 or force_refresh:
132-
cls._refresh_cache()
132+
cls.refresh_cache()
133133
m = {}
134134
for type_id, cm in cls.cache_by_id.items():
135135
type_name = cls.get_name_for_id(type_id)
@@ -165,7 +165,7 @@ def get_attr_id_for_name(cls, set_name: str, attr_name: str) -> Optional[str]:
165165
# If found, return straight away
166166
return attr_id
167167
# Otherwise, refresh the cache and look again (could be stale)
168-
cls._refresh_cache()
168+
cls.refresh_cache()
169169
if sub_map := cls.map_attr_name_to_id.get(set_id):
170170
return sub_map.get(attr_name)
171171
return None
@@ -180,7 +180,7 @@ def get_attr_name_for_id(cls, set_id: str, attr_id: str) -> Optional[str]:
180180
attr_name = sub_map.get(attr_id)
181181
if attr_name:
182182
return attr_name
183-
cls._refresh_cache()
183+
cls.refresh_cache()
184184
if sub_map := cls.map_attr_id_to_name.get(set_id):
185185
return sub_map.get(attr_id)
186186
return None
@@ -200,7 +200,7 @@ def get_attributes_for_search_results(cls, set_name: str) -> Optional[list[str]]
200200
if set_id := cls.get_id_for_name(set_name):
201201
if dot_names := cls._get_attributes_for_search_results(set_id):
202202
return dot_names
203-
cls._refresh_cache()
203+
cls.refresh_cache()
204204
return cls._get_attributes_for_search_results(set_id)
205205
return None
206206

pyatlan/client/atlan.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,22 @@ def create_typedef(self, typedef: TypeDef) -> TypeDefResponse:
495495
raw_json = self._call_api(
496496
CREATE_TYPE_DEFS, request_obj=payload, exclude_unset=False
497497
)
498+
if isinstance(typedef, ClassificationDef):
499+
from pyatlan.cache.classification_cache import ClassificationCache
500+
ClassificationCache.refresh_cache()
501+
if isinstance(typedef, CustomMetadataDef):
502+
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
503+
CustomMetadataCache.refresh_cache()
498504
return TypeDefResponse(**raw_json)
499505

500506
def purge_typedef(self, internal_name: str) -> None:
501507
self._call_api(DELETE_TYPE_DEF_BY_NAME.format_path_with_params(internal_name))
508+
# TODO: if we know which kind of typedef is being purged, we only need
509+
# to refresh that particular cache
510+
from pyatlan.cache.classification_cache import ClassificationCache
511+
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache
512+
ClassificationCache.refresh_cache()
513+
CustomMetadataCache.refresh_cache()
502514

503515
@validate_arguments()
504516
def add_classifications(

0 commit comments

Comments
 (0)