Skip to content

Commit 871d4f6

Browse files
committed
Added terms property to Referenceable and append_terms method to AtlanClient
1 parent 3413ab3 commit 871d4f6

6 files changed

Lines changed: 2669 additions & 43 deletions

File tree

pyatlan/client/atlan.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -603,22 +603,21 @@ def replace_custom_metadata(self, guid: str, custom_metadata: CustomMetadata):
603603
custom_metadata_request,
604604
)
605605

606+
@validate_arguments()
606607
def append_terms(
607608
self, guid: str, asset_type: Type[A], terms: list[AtlasGlossaryTerm]
608-
) -> Optional[A]:
609+
) -> A:
609610
asset = self.get_asset_by_guid(guid=guid, asset_type=asset_type)
610611
if not terms:
611612
return asset
612-
existing_terms = asset.attributes.meanings
613613
replacement_terms: list[AtlasGlossaryTerm] = []
614-
if existing_terms:
615-
for term in existing_terms:
616-
if term.relationship_status != "DELETED":
617-
replacement_terms.append(term)
614+
if existing_terms := asset.terms:
615+
replacement_terms.extend(
616+
term for term in existing_terms if term.relationship_status != "DELETED"
617+
)
618618
replacement_terms.extend(terms)
619619
asset.attributes.meanings = replacement_terms
620620
response = self.upsert(entity=asset)
621-
assets = response.assets_updated(asset_type=asset_type)
622-
if assets:
621+
if assets := response.assets_updated(asset_type=asset_type):
623622
return assets[0]
624-
return None
623+
return asset

pyatlan/generator/templates/entity.jinja2

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ def validate_required_fields(field_names:list[str], values:list[Any]):
7171
raise ValueError(f"{field_name} is required")
7272
if isinstance(value, str) and not value.strip():
7373
raise ValueError(f"{field_name} cannot be blank")
74-
{%- macro gen_properties(attribute_defs) %}
74+
{%- macro gen_properties(attribute_defs, additional_names=[]) %}
7575
_convience_properties: ClassVar[list[str]] = [
7676
{%- for attribute_def in attribute_defs %}
7777
"{{ attribute_def.name | to_snake_case }}",
78-
{%- endfor %}]
78+
{%- endfor %}
79+
{%- for name in additional_names %}
80+
"{{ name }}",
81+
{%- endfor %}]
82+
7983
{%- for attribute_def in attribute_defs %}
8084
{%- set type = attribute_def.typeName | get_type %}
8185
{%- set property_type %}{% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %}{% endset %}
@@ -107,7 +111,19 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
107111
return object.__setattr__(self, name, value)
108112
super().__setattr__( name, value)
109113

110-
{{ gen_properties(entity_def.attribute_defs) }}
114+
{{ gen_properties(entity_def.attribute_defs, ["terms"]) }}
115+
116+
@property
117+
def terms(self) -> list[AtlasGlossaryTerm]:
118+
if self.attributes is None:
119+
self.attributes = self.Attributes()
120+
return [] if self.attributes.meanings is None else self.attributes.meanings
121+
122+
@terms.setter
123+
def terms(self, terms: list[AtlasGlossaryTerm]):
124+
if self.attributes is None:
125+
self.attributes = self.Attributes()
126+
self.attributes.meanings = terms
111127

112128
{%- if entity_def.name == "Referenceable" %}
113129

0 commit comments

Comments
 (0)