Skip to content

Commit 39ac36c

Browse files
committed
[generator] Fixed generator to handle relationships that have both ends pointing to the same type
1 parent dfb50b8 commit 39ac36c

File tree

4 files changed

+25
-146
lines changed

4 files changed

+25
-146
lines changed

pyatlan/generator/templates/custom_relationship.jinja2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class {{ relationship_info.name | to_cls_name }}(RelationshipAttributes):
5757
super().__init__(**data)
5858
__pydantic_self__.__fields_set__.update(["type_name", "relationship_type"])
5959

60+
{% if relationship_info.end_def1 != relationship_info.end_def2 %}
6061
class {{ relationship_info.end_def2["name"] | to_cls_name }}(Asset):
6162
type_name: str = Field(
6263
default="{{ relationship_info.name }}",
@@ -78,6 +79,7 @@ class {{ relationship_info.name | to_cls_name }}(RelationshipAttributes):
7879
def __init__(__pydantic_self__, **data: Any) -> None:
7980
super().__init__(**data)
8081
__pydantic_self__.__fields_set__.update(["type_name", "relationship_type"])
82+
{% endif %}
8183

8284
def {{ relationship_info.end_def1["name"] | to_snake_case }}(
8385
self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
@@ -98,6 +100,7 @@ class {{ relationship_info.name | to_cls_name }}(RelationshipAttributes):
98100
relationship_attributes=self,
99101
)
100102

103+
{% if relationship_info.end_def1 != relationship_info.end_def2 %}
101104
def {{ relationship_info.end_def2["name"] | to_snake_case }}(
102105
self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
103106
) -> {{ relationship_info.name | to_cls_name }}.{{ relationship_info.end_def2["name"] | to_cls_name }}:
@@ -116,8 +119,11 @@ class {{ relationship_info.name | to_cls_name }}(RelationshipAttributes):
116119
semantic=semantic,
117120
relationship_attributes=self,
118121
)
122+
{% endif %}
119123

120124

121125
{{ relationship_info.name | to_cls_name }}.{{ relationship_info.end_def1["name"] | to_cls_name }}.update_forward_refs()
126+
{% if relationship_info.end_def1 != relationship_info.end_def2 -%}
122127
{{ relationship_info.name | to_cls_name }}.{{ relationship_info.end_def2["name"] | to_cls_name }}.update_forward_refs()
128+
{% endif -%}
123129
{{ relationship_info.name | to_cls_name }}.update_forward_refs()

pyatlan/model/assets/relations/atlas_glossary_antonym.py

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pyatlan.model.assets import Asset
88
from pyatlan.model.assets.relations import RelationshipAttributes
99
from pyatlan.model.core import AtlanObject
10-
from pyatlan.model.enums import AtlasGlossaryTermRelationshipStatus
10+
from pyatlan.model.enums import AtlasGlossaryTermRelationshipStatus, SaveSemantic
1111

1212

1313
class AtlasGlossaryAntonym(RelationshipAttributes):
@@ -71,68 +71,25 @@ def __init__(__pydantic_self__, **data: Any) -> None:
7171
super().__init__(**data)
7272
__pydantic_self__.__fields_set__.update(["type_name", "relationship_type"])
7373

74-
75-
# class Antonyms(Asset):
76-
# type_name: str = Field(
77-
# default="AtlasGlossaryAntonym",
78-
# description="Terms that have the opposite (or near opposite) meaning, in the same language.",
79-
# )
80-
# relationship_type: str = Field(
81-
# default="AtlasGlossaryAntonym",
82-
# description="Fixed typeName for AtlasGlossaryAntonym.",
83-
# )
84-
# relationship_attributes: AtlasGlossaryAntonym = Field(
85-
# default=None,
86-
# description="Attributes of the AtlasGlossaryAntonym.",
87-
# )
88-
89-
# @validator("type_name")
90-
# def validate_type_name(cls, v):
91-
# return v
92-
93-
# def __init__(__pydantic_self__, **data: Any) -> None:
94-
# super().__init__(**data)
95-
# __pydantic_self__.__fields_set__.update(["type_name", "relationship_type"])
96-
97-
# def antonyms(
98-
# self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
99-
# ) -> AtlasGlossaryAntonym.Antonyms:
100-
# if related.guid:
101-
# return AtlasGlossaryAntonym.Antonyms._create_ref(
102-
# type_name=related.type_name,
103-
# guid=related.guid,
104-
# semantic=semantic,
105-
# relationship_attributes=self,
106-
# )
107-
108-
# # If the related asset does not have a GUID, we use qualifiedName
109-
# return AtlasGlossaryAntonym.Antonyms._create_ref(
110-
# type_name=related.type_name,
111-
# unique_attributes={"qualifiedName": related.qualified_name},
112-
# semantic=semantic,
113-
# relationship_attributes=self,
114-
# )
115-
116-
# def antonyms(
117-
# self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
118-
# ) -> AtlasGlossaryAntonym.Antonyms:
119-
# if related.guid:
120-
# return AtlasGlossaryAntonym.Antonyms._create_ref(
121-
# type_name=related.type_name,
122-
# guid=related.guid,
123-
# semantic=semantic,
124-
# relationship_attributes=self,
125-
# )
126-
127-
# # If the related asset does not have a GUID, we use qualifiedName
128-
# return AtlasGlossaryAntonym.Antonyms._create_ref(
129-
# type_name=related.type_name,
130-
# unique_attributes={"qualifiedName": related.qualified_name},
131-
# semantic=semantic,
132-
# relationship_attributes=self,
133-
# )
74+
def antonyms(
75+
self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
76+
) -> AtlasGlossaryAntonym.Antonyms:
77+
if related.guid:
78+
return AtlasGlossaryAntonym.Antonyms._create_ref(
79+
type_name=related.type_name,
80+
guid=related.guid,
81+
semantic=semantic,
82+
relationship_attributes=self,
83+
)
84+
85+
# If the related asset does not have a GUID, we use qualifiedName
86+
return AtlasGlossaryAntonym.Antonyms._create_ref(
87+
type_name=related.type_name,
88+
unique_attributes={"qualifiedName": related.qualified_name},
89+
semantic=semantic,
90+
relationship_attributes=self,
91+
)
13492

13593

136-
# AtlasGlossaryAntonym.Antonyms.update_forward_refs()
13794
AtlasGlossaryAntonym.Antonyms.update_forward_refs()
13895
AtlasGlossaryAntonym.update_forward_refs()

pyatlan/model/assets/relations/atlas_glossary_related_term.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,6 @@ def __init__(__pydantic_self__, **data: Any) -> None:
7171
super().__init__(**data)
7272
__pydantic_self__.__fields_set__.update(["type_name", "relationship_type"])
7373

74-
# class SeeAlso(Asset):
75-
# type_name: str = Field(
76-
# default="AtlasGlossaryRelatedTerm",
77-
# description="Linked terms that may also be of interest.",
78-
# )
79-
# relationship_type: str = Field(
80-
# default="AtlasGlossaryRelatedTerm",
81-
# description="Fixed typeName for AtlasGlossaryRelatedTerm.",
82-
# )
83-
# relationship_attributes: AtlasGlossaryRelatedTerm = Field(
84-
# default=None,
85-
# description="Attributes of the AtlasGlossaryRelatedTerm.",
86-
# )
87-
88-
# @validator("type_name")
89-
# def validate_type_name(cls, v):
90-
# return v
91-
92-
# def __init__(__pydantic_self__, **data: Any) -> None:
93-
# super().__init__(**data)
94-
# __pydantic_self__.__fields_set__.update(["type_name", "relationship_type"])
95-
9674
def see_also(
9775
self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
9876
) -> AtlasGlossaryRelatedTerm.SeeAlso:
@@ -112,26 +90,6 @@ def see_also(
11290
relationship_attributes=self,
11391
)
11492

115-
# def see_also(
116-
# self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
117-
# ) -> AtlasGlossaryRelatedTerm.SeeAlso:
118-
# if related.guid:
119-
# return AtlasGlossaryRelatedTerm.SeeAlso._create_ref(
120-
# type_name=related.type_name,
121-
# guid=related.guid,
122-
# semantic=semantic,
123-
# relationship_attributes=self,
124-
# )
125-
126-
# # If the related asset does not have a GUID, we use qualifiedName
127-
# return AtlasGlossaryRelatedTerm.SeeAlso._create_ref(
128-
# type_name=related.type_name,
129-
# unique_attributes={"qualifiedName": related.qualified_name},
130-
# semantic=semantic,
131-
# relationship_attributes=self,
132-
# )
133-
13493

13594
AtlasGlossaryRelatedTerm.SeeAlso.update_forward_refs()
136-
# AtlasGlossaryRelatedTerm.SeeAlso.update_forward_refs()
13795
AtlasGlossaryRelatedTerm.update_forward_refs()

pyatlan/model/assets/relations/atlas_glossary_synonym.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,6 @@ def __init__(__pydantic_self__, **data: Any) -> None:
7171
super().__init__(**data)
7272
__pydantic_self__.__fields_set__.update(["type_name", "relationship_type"])
7373

74-
# class Synonyms(Asset):
75-
# type_name: str = Field(
76-
# default="AtlasGlossarySynonym",
77-
# description="Terms that have the same (or a very similar) meaning, in the same language.",
78-
# )
79-
# relationship_type: str = Field(
80-
# default="AtlasGlossarySynonym",
81-
# description="Fixed typeName for AtlasGlossarySynonym.",
82-
# )
83-
# relationship_attributes: AtlasGlossarySynonym = Field(
84-
# default=None,
85-
# description="Attributes of the AtlasGlossarySynonym.",
86-
# )
87-
88-
# @validator("type_name")
89-
# def validate_type_name(cls, v):
90-
# return v
91-
92-
# def __init__(__pydantic_self__, **data: Any) -> None:
93-
# super().__init__(**data)
94-
# __pydantic_self__.__fields_set__.update(["type_name", "relationship_type"])
95-
9674
def synonyms(
9775
self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
9876
) -> AtlasGlossarySynonym.Synonyms:
@@ -112,26 +90,6 @@ def synonyms(
11290
relationship_attributes=self,
11391
)
11492

115-
# def synonyms(
116-
# self, related: Asset, semantic: SaveSemantic = SaveSemantic.REPLACE
117-
# ) -> AtlasGlossarySynonym.Synonyms:
118-
# if related.guid:
119-
# return AtlasGlossarySynonym.Synonyms._create_ref(
120-
# type_name=related.type_name,
121-
# guid=related.guid,
122-
# semantic=semantic,
123-
# relationship_attributes=self,
124-
# )
125-
126-
# # If the related asset does not have a GUID, we use qualifiedName
127-
# return AtlasGlossarySynonym.Synonyms._create_ref(
128-
# type_name=related.type_name,
129-
# unique_attributes={"qualifiedName": related.qualified_name},
130-
# semantic=semantic,
131-
# relationship_attributes=self,
132-
# )
133-
13493

13594
AtlasGlossarySynonym.Synonyms.update_forward_refs()
136-
# AtlasGlossarySynonym.Synonyms.update_forward_refs()
13795
AtlasGlossarySynonym.update_forward_refs()

0 commit comments

Comments
 (0)