Skip to content

Commit bbc60b9

Browse files
committed
[fix/tests] Resolved pickle errors for thread.lock objects in suggestions and fix tag cache import issues
1 parent 442b375 commit bbc60b9

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

pyatlan/model/suggestions.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ class Suggestions(AtlanObject):
5858
AGG_OWNER_GROUPS: ClassVar[str] = "group_by_ownerGroups"
5959
AGG_ATLAN_TAGS: ClassVar[str] = "group_by_tags"
6060
AGG_TERMS: ClassVar[str] = "group_by_terms"
61-
62-
client: AtlanClient = Field(
63-
default_factory=lambda: AtlanClient.get_current_client()
64-
)
6561
"""Client through which to find suggestions."""
6662
asset: Optional[Asset] = Field(default=None)
6763
"""Asset for which to find suggestions."""
@@ -211,24 +207,22 @@ def where_not(self, query: Query) -> Suggestions:
211207
clone.where_nots.append(query)
212208
return clone
213209

214-
def finder(self, asset: Asset, client: Optional[AtlanClient] = None) -> Suggestions:
210+
def finder(self, asset: Asset) -> Suggestions:
215211
"""
216212
Build a suggestion finder against
217213
the provided Atlan tenant for the provided asset
218214
219-
:param: client connectivity to an Atlan tenant
220215
:param: asset for which to find suggestions
221216
:return: the start of a suggestion finder
222217
for the provided asset, against the specified tenant
223218
"""
224-
client = AtlanClient.get_current_client() if not client else client
225-
self.client = client
226219
self.asset = asset
227220
return self
228221

229-
def get(self) -> SuggestionResponse:
222+
def get(self, client: Optional[AtlanClient] = None) -> SuggestionResponse:
230223
asset_name = ""
231224
all_types = []
225+
client = client or AtlanClient.get_current_client()
232226

233227
if self.asset and self.asset.name:
234228
asset_name = self.asset.name
@@ -302,12 +296,17 @@ def get(self) -> SuggestionResponse:
302296
)
303297

304298
search_request = search.to_request()
305-
search_response = self.client.search(criteria=search_request)
299+
search_response = client.search(criteria=search_request)
306300
aggregations = search_response.aggregations
307301
suggestion_response = SuggestionResponse()
308302

309303
for include in self.includes:
310-
self._build_response(include, suggestion_response, aggregations)
304+
self._build_response(
305+
client,
306+
include,
307+
suggestion_response,
308+
aggregations,
309+
)
311310
return suggestion_response
312311

313312
def _get_descriptions(self, result: Aggregations, field: AtlanField):
@@ -336,13 +335,13 @@ def _get_terms(self, result: Aggregations):
336335
)
337336
return results
338337

339-
def _get_tags(self, result: Aggregations):
338+
def _get_tags(self, client: AtlanClient, result: Aggregations):
340339
results = []
341340
if isinstance(result, AggregationBucketResult):
342341
for bucket in result.buckets:
343342
count = bucket.doc_count
344343
value = bucket.key
345-
name = self.client.atlan_tag_cache.get_name_for_id(value)
344+
name = client.atlan_tag_cache.get_name_for_id(value)
346345
if count and name:
347346
results.append(
348347
SuggestionResponse.SuggestedItem(count=count, value=name)
@@ -361,7 +360,7 @@ def _get_others(self, result: Aggregations):
361360
)
362361
return results
363362

364-
def _build_response(self, include, suggestion_response, aggregations):
363+
def _build_response(self, client, include, suggestion_response, aggregations):
365364
if include == Suggestions.TYPE.SYSTEM_DESCRIPTION:
366365
suggestion_response.system_descriptions.extend(
367366
self._get_descriptions(
@@ -390,9 +389,7 @@ def _build_response(self, include, suggestion_response, aggregations):
390389
)
391390
elif include == Suggestions.TYPE.TAGS:
392391
suggestion_response.atlan_tags.extend(
393-
self._get_tags(
394-
aggregations.get(Suggestions.AGG_ATLAN_TAGS),
395-
)
392+
self._get_tags(client, aggregations.get(Suggestions.AGG_ATLAN_TAGS))
396393
)
397394
elif include == Suggestions.TYPE.TERMS:
398395
suggestion_response.assigned_terms.extend(
@@ -402,7 +399,10 @@ def _build_response(self, include, suggestion_response, aggregations):
402399
)
403400

404401
def apply(
405-
self, allow_multiple: bool = False, batch: Optional[Batch] = None
402+
self,
403+
allow_multiple: bool = False,
404+
batch: Optional[Batch] = None,
405+
client: Optional[AtlanClient] = None,
406406
) -> Optional[AssetMutationResponse]:
407407
"""
408408
Find the requested suggestions and apply the top suggestions as changes to the asset.
@@ -416,14 +416,16 @@ def apply(
416416
:param allow_multiple: if `True`, allow multiple suggestions to be applied
417417
to the asset (up to `max_suggestions` requested), i.e: for owners, terms and tags
418418
:param batch: (optional) the batch in which you want to apply the top suggestions as changes to the asset
419+
:param client: (optional) client connectivity to an Atlan tenant
419420
"""
421+
client = client or AtlanClient.get_current_client()
420422
if batch:
421-
return batch.add(self._apply(allow_multiple).asset)
422-
result = self._apply(allow_multiple)
423-
return self.client.save(result.asset, result.include_tags)
423+
return batch.add(self._apply(client, allow_multiple).asset)
424+
result = self._apply(client, allow_multiple)
425+
return client.save(result.asset, result.include_tags)
424426

425-
def _apply(self, allow_multiple: bool):
426-
response = self.get()
427+
def _apply(self, client: AtlanClient, allow_multiple: bool):
428+
response = self.get(client)
427429
asset = self.asset.trim_to_required() # type: ignore[union-attr]
428430

429431
description_to_apply = self._get_description_to_apply(response)

tests/integration/atlan_tag_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import pytest
1010

11-
from pyatlan.cache.atlan_tag_cache import AtlanTagCache
1211
from pyatlan.client.atlan import AtlanClient
1312
from pyatlan.errors import AtlanError
1413
from pyatlan.model.atlan_image import AtlanImage
@@ -116,12 +115,12 @@ def test_atlan_tag_with_image(atlan_tag_with_image):
116115
assert atlan_tag_with_image.options.get("iconType") == TagIconType.IMAGE.value
117116

118117

119-
def test_atlan_tag_cache(atlan_tag_with_image):
118+
def test_atlan_tag_cache(client: AtlanClient, atlan_tag_with_image):
120119
cls_name = CLS_IMAGE
121-
cls_id = AtlanTagCache.get_id_for_name(cls_name)
120+
cls_id = client.atlan_tag_cache.get_id_for_name(cls_name)
122121
assert cls_id
123122
assert cls_id == atlan_tag_with_image.name
124-
cls_name_found = AtlanTagCache.get_name_for_id(cls_id)
123+
cls_name_found = client.atlan_tag_cache.get_name_for_id(cls_id)
125124
assert cls_name_found
126125
assert cls_name_found == cls_name
127126

0 commit comments

Comments
 (0)