Skip to content

Commit b3a2b0b

Browse files
authored
Merge pull request #686 from atlanhq/APP-7827
APP-7827: Added support for `AttributeDef.Options.applicable_ai_asset_types`
2 parents 5a52a5b + d4a1006 commit b3a2b0b

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

pyatlan/model/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"AtlasGlossaryTerm",
1515
]
1616
]
17+
AIAssetTypes = Set[Literal["AIApplication", "AIModel"]]
1718
OtherAssetTypes = Set[Literal["File"]]
1819
AssetTypes = Set[
1920
Literal[

pyatlan/model/typedef.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pyatlan.errors import ErrorCode
2222
from pyatlan.model.atlan_image import AtlanImage
2323
from pyatlan.model.constants import (
24+
AIAssetTypes,
2425
AssetTypes,
2526
DomainTypes,
2627
EntityTypes,
@@ -192,6 +193,7 @@
192193
"DataProduct",
193194
}
194195

196+
_all_ai_asset_types: AIAssetTypes = {"AIApplication", "AIModel"}
195197
_all_other_types: OtherAssetTypes = {"File"}
196198

197199

@@ -494,6 +496,12 @@ class Options(AtlanObject):
494496
"These cover asset types in data products and data domains. "
495497
"Only assets of one of these types will have this attribute available.",
496498
)
499+
applicable_ai_asset_types: Optional[str] = Field(
500+
default=None,
501+
alias="aiAssetsTypeList",
502+
description="AI asset type names to which this attribute is restricted. "
503+
"Only AI assets of the specified types will have this attribute available.",
504+
)
497505
applicable_other_asset_types: Optional[str] = Field(
498506
default=None,
499507
alias="otherAssetTypeList",
@@ -639,6 +647,7 @@ def __setattr__(self, name, value):
639647
"applicable_connections",
640648
"applicable_glossaries",
641649
"applicable_domains",
650+
"applicable_ai_asset_types",
642651
]
643652

644653
@property
@@ -747,6 +756,30 @@ def applicable_domain_types(self, domain_types: DomainTypes):
747756
)
748757
self.options.applicable_domain_types = json.dumps(list(domain_types))
749758

759+
@property
760+
def applicable_ai_asset_types(self) -> AIAssetTypes:
761+
"""
762+
AI asset type names to which this attribute is restricted.
763+
Only AI assets of the specified types will have this attribute available.
764+
"""
765+
if self.options and self.options.applicable_ai_asset_types:
766+
return set(json.loads(self.options.applicable_ai_asset_types))
767+
return set()
768+
769+
@applicable_ai_asset_types.setter
770+
def applicable_ai_asset_types(self, ai_asset_types: AIAssetTypes):
771+
if self.options is None:
772+
raise ErrorCode.MISSING_OPTIONS.exception_with_parameters()
773+
if not isinstance(ai_asset_types, set):
774+
raise ErrorCode.INVALID_PARAMETER_TYPE.exception_with_parameters(
775+
"applicable_ai_asset_types", AIAssetTypes
776+
)
777+
if not ai_asset_types.issubset(_all_ai_asset_types):
778+
raise ErrorCode.INVALID_PARAMETER_VALUE.exception_with_parameters(
779+
ai_asset_types, "applicable_ai_asset_types", _all_ai_asset_types
780+
)
781+
self.options.applicable_ai_asset_types = json.dumps(list(ai_asset_types))
782+
750783
@property
751784
def applicable_other_asset_types(self) -> OtherAssetTypes:
752785
"""
@@ -855,6 +888,7 @@ def create(
855888
applicable_other_asset_types: Optional[OtherAssetTypes] = None,
856889
applicable_domains: Optional[Set[str]] = None,
857890
applicable_domain_types: Optional[DomainTypes] = None,
891+
applicable_ai_asset_types: Optional[AIAssetTypes] = None,
858892
description: Optional[str] = None,
859893
) -> AttributeDef:
860894
from pyatlan.utils import validate_required_fields
@@ -918,6 +952,7 @@ def create(
918952
applicable_glossaries or _get_all_qualified_names(client, "AtlasGlossary")
919953
)
920954
attr_def.applicable_domains = applicable_domains or _all_domains
955+
attr_def.applicable_ai_asset_types = applicable_ai_asset_types or set()
921956
return attr_def
922957

923958
def is_archived(self) -> bool:

tests/unit/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pyatlan.model.assets import AtlasGlossary
22
from pyatlan.model.constants import (
3+
AIAssetTypes,
34
AssetTypes,
45
DomainTypes,
56
EntityTypes,
@@ -599,6 +600,8 @@
599600

600601
APPLICABLE_DOMAIN_TYPES = "applicable_domain_types"
601602

603+
APPLICABLE_AI_ASSET_TYPES = "applicable_ai_asset_types"
604+
602605
APPLICABLE_ASSET_TYPES = "applicable_asset_types"
603606

604607
TEST_ENUM_DEF = {
@@ -721,6 +724,16 @@
721724
{"Bogus"},
722725
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_domain_types'.",
723726
),
727+
(
728+
APPLICABLE_AI_ASSET_TYPES,
729+
1,
730+
f"ATLAN-PYTHON-400-048 Invalid parameter type for applicable_ai_asset_types should be {AIAssetTypes}",
731+
),
732+
(
733+
APPLICABLE_AI_ASSET_TYPES,
734+
{"Bogus"},
735+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_ai_asset_types'.",
736+
),
724737
(
725738
APPLICABLE_OTHER_ASSET_TYPES,
726739
1,

tests/unit/test_typedef_model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
StructDef,
2525
TypeDef,
2626
TypeDefResponse,
27+
_all_ai_asset_types,
2728
_all_domain_types,
2829
_all_glossary_types,
2930
_all_other_types,
3031
_complete_type_list,
3132
)
3233
from pyatlan.model.utils import to_camel_case, to_snake_case
3334
from tests.unit.constants import (
35+
APPLICABLE_AI_ASSET_TYPES,
3436
APPLICABLE_ASSET_TYPES,
3537
APPLICABLE_CONNECTIONS,
3638
APPLICABLE_DOMAIN_TYPES,
@@ -363,6 +365,7 @@ def sut(self, client: AtlanClient) -> AttributeDef:
363365
(APPLICABLE_ASSET_TYPES, {"Table"}),
364366
(APPLICABLE_GLOSSARY_TYPES, {"AtlasGlossary"}),
365367
(APPLICABLE_DOMAIN_TYPES, {"DataDomain", "DataProduct"}),
368+
(APPLICABLE_AI_ASSET_TYPES, {"AIApplication", "AIModel"}),
366369
(APPLICABLE_OTHER_ASSET_TYPES, {"File"}),
367370
(APPLICABLE_ENTITY_TYPES, {"Asset"}),
368371
],
@@ -397,6 +400,7 @@ def test_applicable_types_with_invalid_type_raises_invalid_request_error(
397400
(APPLICABLE_ASSET_TYPES, {random.choice(list(_complete_type_list))}),
398401
(APPLICABLE_GLOSSARY_TYPES, {random.choice(list(_all_glossary_types))}),
399402
(APPLICABLE_DOMAIN_TYPES, {random.choice(list(_all_domain_types))}),
403+
(APPLICABLE_AI_ASSET_TYPES, {random.choice(list(_all_ai_asset_types))}),
400404
(APPLICABLE_OTHER_ASSET_TYPES, {random.choice(list(_all_other_types))}),
401405
(APPLICABLE_ENTITY_TYPES, {"Asset"}),
402406
(APPLICABLE_CONNECTIONS, {"default/snowflake/1699268171"}),
@@ -424,6 +428,7 @@ def test_attribute_create_with_limited_applicability(self, client: AtlanClient):
424428
"default/snowflake/16992681799",
425429
},
426430
applicable_domains={"default/domain/uuBI8WSqeom1PXs7oo20L/super"},
431+
applicable_ai_asset_types={"AIModel", "AIApplication"},
427432
)
428433
attribute_def_with_limited = AttributeDef.create(
429434
client=client,

0 commit comments

Comments
 (0)