@@ -385,6 +385,14 @@ def find_purposes_by_name(
385
385
allow_multiple = True ,
386
386
)
387
387
388
+ def _normalize_search_fields (
389
+ self ,
390
+ fields : Optional [Union [List [str ], List [AtlanField ]]],
391
+ ) -> List [str ]:
392
+ if not fields :
393
+ return []
394
+ return [f .atlan_field_name if isinstance (f , AtlanField ) else f for f in fields ]
395
+
388
396
@validate_arguments (config = dict (arbitrary_types_allowed = True ))
389
397
def get_by_qualified_name (
390
398
self ,
@@ -408,29 +416,27 @@ def get_by_qualified_name(
408
416
:raises NotFoundError: if the asset does not exist
409
417
:raises AtlanError: on any API communication issue
410
418
"""
411
- from pyatlan .client .atlan import AtlanClient
412
419
from pyatlan .model .fluent_search import FluentSearch
413
420
414
421
query_params = {
415
422
"attr:qualifiedName" : qualified_name ,
416
423
"minExtInfo" : min_ext_info ,
417
424
"ignoreRelationships" : ignore_relationships ,
418
425
}
419
- attributes = attributes or []
420
- related_attributes = related_attributes or []
426
+ attributes = self . _normalize_search_fields ( attributes )
427
+ related_attributes = self . _normalize_search_fields ( related_attributes )
421
428
422
429
if (attributes and len (attributes )) or (
423
430
related_attributes and len (related_attributes )
424
431
):
425
- client = AtlanClient .get_current_client ()
426
432
search = (
427
433
FluentSearch ().select ().where (Asset .QUALIFIED_NAME .eq (qualified_name ))
428
434
)
429
435
for attribute in attributes :
430
436
search = search .include_on_results (attribute )
431
437
for relation_attribute in related_attributes :
432
438
search = search .include_on_relations (relation_attribute )
433
- results = search .execute (client = client )
439
+ results = search .execute (client = self . _client ) # type: ignore[arg-type]
434
440
if results and results .current_page ():
435
441
first_result = results .current_page ()[0 ]
436
442
if isinstance (first_result , asset_type ):
@@ -482,26 +488,24 @@ def get_by_guid(
482
488
:raises NotFoundError: if the asset does not exist, or is not of the type requested
483
489
:raises AtlanError: on any API communication issue
484
490
"""
485
- from pyatlan .client .atlan import AtlanClient
486
491
from pyatlan .model .fluent_search import FluentSearch
487
492
488
493
query_params = {
489
494
"minExtInfo" : min_ext_info ,
490
495
"ignoreRelationships" : ignore_relationships ,
491
496
}
492
- attributes = attributes or []
493
- related_attributes = related_attributes or []
497
+ attributes = self . _normalize_search_fields ( attributes )
498
+ related_attributes = self . _normalize_search_fields ( related_attributes )
494
499
495
500
if (attributes and len (attributes )) or (
496
501
related_attributes and len (related_attributes )
497
502
):
498
- client = AtlanClient .get_current_client ()
499
503
search = FluentSearch ().select ().where (Asset .GUID .eq (guid ))
500
504
for attribute in attributes :
501
505
search = search .include_on_results (attribute )
502
506
for relation_attribute in related_attributes :
503
507
search = search .include_on_relations (relation_attribute )
504
- results = search .execute (client = client )
508
+ results = search .execute (client = self . _client ) # type: ignore[arg-type]
505
509
if results and results .current_page ():
506
510
first_result = results .current_page ()[0 ]
507
511
if isinstance (first_result , asset_type ):
@@ -892,13 +896,13 @@ def _modify_tags(
892
896
reterieved_asset = self .get_by_qualified_name (
893
897
qualified_name = qualified_name ,
894
898
asset_type = asset_type ,
895
- attributes = [AtlasGlossaryTerm .ANCHOR . atlan_field_name ],
899
+ attributes = [AtlasGlossaryTerm .ANCHOR ], # type: ignore[arg-type]
896
900
)
897
901
if asset_type in (AtlasGlossaryTerm , AtlasGlossaryCategory ):
898
902
updated_asset = asset_type .updater (
899
903
qualified_name = qualified_name ,
900
904
name = reterieved_asset .name ,
901
- glossary_guid = reterieved_asset .anchor .guid , # type: ignore
905
+ glossary_guid = reterieved_asset .anchor .guid , # type: ignore[attr-defined]
902
906
)
903
907
else :
904
908
updated_asset = asset_type .updater (
@@ -1428,10 +1432,8 @@ def append_terms(
1428
1432
:param qualified_name: the qualified_name of the asset to which to link the terms
1429
1433
:returns: the asset that was updated (note that it will NOT contain details of the appended terms)
1430
1434
"""
1431
- from pyatlan .client .atlan import AtlanClient
1432
1435
from pyatlan .model .fluent_search import FluentSearch
1433
1436
1434
- client = AtlanClient .get_current_client ()
1435
1437
if guid :
1436
1438
if qualified_name :
1437
1439
raise ErrorCode .QN_OR_GUID_NOT_BOTH .exception_with_parameters ()
@@ -1440,15 +1442,15 @@ def append_terms(
1440
1442
.select ()
1441
1443
.where (Asset .TYPE_NAME .eq (asset_type .__name__ ))
1442
1444
.where (asset_type .GUID .eq (guid ))
1443
- .execute (client = client )
1445
+ .execute (client = self . _client ) # type: ignore[arg-type]
1444
1446
)
1445
1447
elif qualified_name :
1446
1448
results = (
1447
1449
FluentSearch ()
1448
1450
.select ()
1449
1451
.where (Asset .TYPE_NAME .eq (asset_type .__name__ ))
1450
1452
.where (asset_type .QUALIFIED_NAME .eq (qualified_name ))
1451
- .execute (client = client )
1453
+ .execute (client = self . _client ) # type: ignore[arg-type]
1452
1454
)
1453
1455
else :
1454
1456
raise ErrorCode .QN_OR_GUID .exception_with_parameters ()
@@ -1507,10 +1509,8 @@ def replace_terms(
1507
1509
:param qualified_name: the qualified_name of the asset to which to replace the terms
1508
1510
:returns: the asset that was updated (note that it will NOT contain details of the replaced terms)
1509
1511
"""
1510
- from pyatlan .client .atlan import AtlanClient
1511
1512
from pyatlan .model .fluent_search import FluentSearch
1512
1513
1513
- client = AtlanClient .get_current_client ()
1514
1514
if guid :
1515
1515
if qualified_name :
1516
1516
raise ErrorCode .QN_OR_GUID_NOT_BOTH .exception_with_parameters ()
@@ -1519,15 +1519,15 @@ def replace_terms(
1519
1519
.select ()
1520
1520
.where (Asset .TYPE_NAME .eq (asset_type .__name__ ))
1521
1521
.where (asset_type .GUID .eq (guid ))
1522
- .execute (client = client )
1522
+ .execute (client = self . _client ) # type: ignore[arg-type]
1523
1523
)
1524
1524
elif qualified_name :
1525
1525
results = (
1526
1526
FluentSearch ()
1527
1527
.select ()
1528
1528
.where (Asset .TYPE_NAME .eq (asset_type .__name__ ))
1529
1529
.where (asset_type .QUALIFIED_NAME .eq (qualified_name ))
1530
- .execute (client = client )
1530
+ .execute (client = self . _client ) # type: ignore[arg-type]
1531
1531
)
1532
1532
else :
1533
1533
raise ErrorCode .QN_OR_GUID .exception_with_parameters ()
@@ -1588,10 +1588,8 @@ def remove_terms(
1588
1588
:param qualified_name: the qualified_name of the asset from which to remove the terms
1589
1589
:returns: the asset that was updated (note that it will NOT contain details of the resulting terms)
1590
1590
"""
1591
- from pyatlan .client .atlan import AtlanClient
1592
1591
from pyatlan .model .fluent_search import FluentSearch
1593
1592
1594
- client = AtlanClient .get_current_client ()
1595
1593
if guid :
1596
1594
if qualified_name :
1597
1595
raise ErrorCode .QN_OR_GUID_NOT_BOTH .exception_with_parameters ()
@@ -1600,15 +1598,15 @@ def remove_terms(
1600
1598
.select ()
1601
1599
.where (Asset .TYPE_NAME .eq (asset_type .__name__ ))
1602
1600
.where (asset_type .GUID .eq (guid ))
1603
- .execute (client = client )
1601
+ .execute (client = self . _client ) # type: ignore[arg-type]
1604
1602
)
1605
1603
elif qualified_name :
1606
1604
results = (
1607
1605
FluentSearch ()
1608
1606
.select ()
1609
1607
.where (Asset .TYPE_NAME .eq (asset_type .__name__ ))
1610
1608
.where (asset_type .QUALIFIED_NAME .eq (qualified_name ))
1611
- .execute (client = client )
1609
+ .execute (client = self . _client ) # type: ignore[arg-type]
1612
1610
)
1613
1611
else :
1614
1612
raise ErrorCode .QN_OR_GUID .exception_with_parameters ()
@@ -2567,7 +2565,7 @@ def flush(self) -> Optional[AssetMutationResponse]:
2567
2565
)
2568
2566
results = search .page_size (
2569
2567
max (self ._max_size * 2 , DSL .__fields__ .get ("size" ).default ) # type: ignore[union-attr]
2570
- ).execute (client = self ._client )
2568
+ ).execute (client = self ._client ) # type: ignore[arg-type]
2571
2569
2572
2570
for asset in results :
2573
2571
asset_id = AssetIdentity (
0 commit comments