Skip to content

Commit fd53c3a

Browse files
committed
Add retreive_minimal method to AtlanClient
1 parent c67add3 commit fd53c3a

3 files changed

Lines changed: 33 additions & 22 deletions

File tree

pyatlan/client/atlan.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def get_asset_by_qualified_name(
320320
return asset
321321
except AtlanError as ae:
322322
if ae.status_code == HTTPStatus.NOT_FOUND:
323-
raise NotFoundError(message=ae.user_message, code=ae.code)
323+
raise NotFoundError(message=ae.user_message, code=ae.code) from ae
324324
raise ae
325325

326326
@validate_arguments()
@@ -355,9 +355,18 @@ def get_asset_by_guid(
355355
return asset
356356
except AtlanError as ae:
357357
if ae.status_code == HTTPStatus.NOT_FOUND:
358-
raise NotFoundError(message=ae.user_message, code=ae.code)
358+
raise NotFoundError(message=ae.user_message, code=ae.code) from ae
359359
raise ae
360360

361+
@validate_arguments()
362+
def retrieve_minimal(self, guid: str, asset_type: Type[A]) -> A:
363+
return self.get_asset_by_guid(
364+
guid=guid,
365+
asset_type=asset_type,
366+
min_ext_info=True,
367+
ignore_relationships=True,
368+
)
369+
361370
def upsert(
362371
self,
363372
entity: Union[Asset, list[Asset]],
@@ -419,7 +428,6 @@ def get_typedefs(self, type_category: AtlanTypeCategory) -> TypeDefResponse:
419428
return TypeDefResponse(**raw_json)
420429

421430
def create_typedef(self, typedef: TypeDef) -> TypeDefResponse:
422-
payload = None
423431
if isinstance(typedef, ClassificationDef):
424432
# Set up the request payload...
425433
payload = TypeDefResponse(
@@ -463,15 +471,15 @@ def add_classifications(
463471
classification_names: list[str],
464472
propagate: bool = True,
465473
remove_propagation_on_delete: bool = True,
466-
restrict_lineage_propogation: bool = True,
474+
restrict_lineage_propagation: bool = True,
467475
) -> None:
468476
classifications = Classifications(
469477
__root__=[
470478
Classification(
471479
type_name=ClassificationName(display_text=name),
472480
propagate=propagate,
473481
remove_propagations_on_entity_delete=remove_propagation_on_delete,
474-
restrict_propagation_through_lineage=restrict_lineage_propogation,
482+
restrict_propagation_through_lineage=restrict_lineage_propagation,
475483
)
476484
for name in classification_names
477485
]
@@ -528,11 +536,9 @@ def _update_asset_by_attribute(self, asset, asset_type, qualified_name: str):
528536
AssetRequest[Asset](entity=asset),
529537
)
530538
response = AssetMutationResponse(**raw_json)
531-
assets = response.assets_partially_updated(asset_type=asset_type)
532-
if assets:
539+
if assets := response.assets_partially_updated(asset_type=asset_type):
533540
return assets[0]
534-
assets = response.assets_updated(asset_type=asset_type)
535-
if assets:
541+
if assets := response.assets_updated(asset_type=asset_type):
536542
return assets[0]
537543
return None
538544

pyatlan/generator/templates/entity.jinja2

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,25 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
233233
if ba_id is None:
234234
raise ValueError(f"No business attributes with the name: {name} exist")
235235
for a_type in CustomMetadataCache.types_by_asset[self.type_name]:
236-
if hasattr(a_type, "_meta_data_type_name") and a_type._meta_data_type_name == name:
236+
if (
237+
hasattr(a_type, "_meta_data_type_name")
238+
and a_type._meta_data_type_name == name
239+
):
237240
break
238241
else:
239242
raise ValueError(
240243
f"Business attributes {name} are not applicable to {self.type_name}"
241244
)
242-
ba_type = CustomMetadataCache.get_type_for_id(ba_id)
243-
if not ba_type:
245+
if ba_type := CustomMetadataCache.get_type_for_id(ba_id):
246+
return (
247+
ba_type(self.business_attributes[ba_id])
248+
if self.business_attributes and ba_id in self.business_attributes
249+
else ba_type()
250+
)
251+
else:
244252
raise ValueError(
245253
f"Business attributes {name} are not applicable to {self.type_name}"
246254
)
247-
if self.business_attributes and ba_id in self.business_attributes:
248-
return ba_type(self.business_attributes[ba_id])
249-
else:
250-
return ba_type()
251255

252256
def set_business_attribute(self, business_attributes: BusinessAttributes) -> None:
253257
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache

pyatlan/model/assets.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,16 @@ def get_business_attributes(self, name: str) -> BusinessAttributes:
262262
raise ValueError(
263263
f"Business attributes {name} are not applicable to {self.type_name}"
264264
)
265-
ba_type = CustomMetadataCache.get_type_for_id(ba_id)
266-
if not ba_type:
265+
if ba_type := CustomMetadataCache.get_type_for_id(ba_id):
266+
return (
267+
ba_type(self.business_attributes[ba_id])
268+
if self.business_attributes and ba_id in self.business_attributes
269+
else ba_type()
270+
)
271+
else:
267272
raise ValueError(
268273
f"Business attributes {name} are not applicable to {self.type_name}"
269274
)
270-
if self.business_attributes and ba_id in self.business_attributes:
271-
return ba_type(self.business_attributes[ba_id])
272-
else:
273-
return ba_type()
274275

275276
def set_business_attribute(self, business_attributes: BusinessAttributes) -> None:
276277
from pyatlan.cache.custom_metadata_cache import CustomMetadataCache

0 commit comments

Comments
 (0)