@@ -58,10 +58,6 @@ class Suggestions(AtlanObject):
58
58
AGG_OWNER_GROUPS : ClassVar [str ] = "group_by_ownerGroups"
59
59
AGG_ATLAN_TAGS : ClassVar [str ] = "group_by_tags"
60
60
AGG_TERMS : ClassVar [str ] = "group_by_terms"
61
-
62
- client : AtlanClient = Field (
63
- default_factory = lambda : AtlanClient .get_current_client ()
64
- )
65
61
"""Client through which to find suggestions."""
66
62
asset : Optional [Asset ] = Field (default = None )
67
63
"""Asset for which to find suggestions."""
@@ -211,24 +207,22 @@ def where_not(self, query: Query) -> Suggestions:
211
207
clone .where_nots .append (query )
212
208
return clone
213
209
214
- def finder (self , asset : Asset , client : Optional [ AtlanClient ] = None ) -> Suggestions :
210
+ def finder (self , asset : Asset ) -> Suggestions :
215
211
"""
216
212
Build a suggestion finder against
217
213
the provided Atlan tenant for the provided asset
218
214
219
- :param: client connectivity to an Atlan tenant
220
215
:param: asset for which to find suggestions
221
216
:return: the start of a suggestion finder
222
217
for the provided asset, against the specified tenant
223
218
"""
224
- client = AtlanClient .get_current_client () if not client else client
225
- self .client = client
226
219
self .asset = asset
227
220
return self
228
221
229
- def get (self ) -> SuggestionResponse :
222
+ def get (self , client : Optional [ AtlanClient ] = None ) -> SuggestionResponse :
230
223
asset_name = ""
231
224
all_types = []
225
+ client = client or AtlanClient .get_current_client ()
232
226
233
227
if self .asset and self .asset .name :
234
228
asset_name = self .asset .name
@@ -302,12 +296,17 @@ def get(self) -> SuggestionResponse:
302
296
)
303
297
304
298
search_request = search .to_request ()
305
- search_response = self . client .search (criteria = search_request )
299
+ search_response = client .search (criteria = search_request )
306
300
aggregations = search_response .aggregations
307
301
suggestion_response = SuggestionResponse ()
308
302
309
303
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
+ )
311
310
return suggestion_response
312
311
313
312
def _get_descriptions (self , result : Aggregations , field : AtlanField ):
@@ -336,13 +335,13 @@ def _get_terms(self, result: Aggregations):
336
335
)
337
336
return results
338
337
339
- def _get_tags (self , result : Aggregations ):
338
+ def _get_tags (self , client : AtlanClient , result : Aggregations ):
340
339
results = []
341
340
if isinstance (result , AggregationBucketResult ):
342
341
for bucket in result .buckets :
343
342
count = bucket .doc_count
344
343
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 )
346
345
if count and name :
347
346
results .append (
348
347
SuggestionResponse .SuggestedItem (count = count , value = name )
@@ -361,7 +360,7 @@ def _get_others(self, result: Aggregations):
361
360
)
362
361
return results
363
362
364
- def _build_response (self , include , suggestion_response , aggregations ):
363
+ def _build_response (self , client , include , suggestion_response , aggregations ):
365
364
if include == Suggestions .TYPE .SYSTEM_DESCRIPTION :
366
365
suggestion_response .system_descriptions .extend (
367
366
self ._get_descriptions (
@@ -390,9 +389,7 @@ def _build_response(self, include, suggestion_response, aggregations):
390
389
)
391
390
elif include == Suggestions .TYPE .TAGS :
392
391
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 ))
396
393
)
397
394
elif include == Suggestions .TYPE .TERMS :
398
395
suggestion_response .assigned_terms .extend (
@@ -402,7 +399,10 @@ def _build_response(self, include, suggestion_response, aggregations):
402
399
)
403
400
404
401
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 ,
406
406
) -> Optional [AssetMutationResponse ]:
407
407
"""
408
408
Find the requested suggestions and apply the top suggestions as changes to the asset.
@@ -416,14 +416,16 @@ def apply(
416
416
:param allow_multiple: if `True`, allow multiple suggestions to be applied
417
417
to the asset (up to `max_suggestions` requested), i.e: for owners, terms and tags
418
418
: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
419
420
"""
421
+ client = client or AtlanClient .get_current_client ()
420
422
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 )
424
426
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 )
427
429
asset = self .asset .trim_to_required () # type: ignore[union-attr]
428
430
429
431
description_to_apply = self ._get_description_to_apply (response )
0 commit comments