Skip to content

Commit fca2cff

Browse files
authored
Merge pull request #645 from atlanhq/APP-6975
APP-6975 : Change the applicable_asset_types validator to use import approach
2 parents f22db78 + e003fc7 commit fca2cff

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

pyatlan/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ class ErrorCode(Enum):
484484
INVALID_PARAMETER_VALUE = (
485485
400,
486486
"ATLAN-PYTHON-400-051",
487-
"{0} is an invalid value for {1} should be in {2}.",
488-
"Check that value you are using is valid.",
487+
"Invalid value(s) {0} provided for '{1}'. Expected one or more of the supported {2}.",
488+
"Verify that each value corresponds to a valid SDK asset type.",
489489
InvalidRequestError,
490490
)
491491
ASSET_CAN_NOT_BE_ARCHIVED = (

pyatlan/model/typedef.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3+
import importlib
34
import json
45
import time
5-
from typing import Any, Callable, ClassVar, Dict, List, Optional, Set, cast
6+
from typing import Any, Callable, ClassVar, Dict, List, Optional, Set, Union, cast
67

78
from pydantic.v1 import Field, PrivateAttr
89

@@ -651,7 +652,7 @@ def applicable_entity_types(self, entity_types: EntityTypes):
651652
self.options.applicable_entity_types = json.dumps(list(entity_types))
652653

653654
@property
654-
def applicable_asset_types(self) -> AssetTypes:
655+
def applicable_asset_types(self) -> Union[Set[str], AssetTypes]:
655656
"""
656657
Asset type names to which to restrict the attribute.
657658
Only assets of one of these types will have this attribute available.
@@ -662,16 +663,26 @@ def applicable_asset_types(self) -> AssetTypes:
662663
return set()
663664

664665
@applicable_asset_types.setter
665-
def applicable_asset_types(self, asset_types: AssetTypes):
666+
def applicable_asset_types(self, asset_types: Union[Set[str], AssetTypes]):
666667
if self.options is None:
667668
raise ErrorCode.MISSING_OPTIONS.exception_with_parameters()
669+
668670
if not isinstance(asset_types, set):
669671
raise ErrorCode.INVALID_PARAMETER_TYPE.exception_with_parameters(
670672
"applicable_asset_types", AssetTypes
671673
)
672-
if not asset_types.issubset(_complete_type_list):
674+
675+
# Validate asset type names against SDK asset classes
676+
invalid_types = {
677+
asset_type
678+
for asset_type in asset_types
679+
if not getattr(
680+
importlib.import_module("pyatlan.model.assets"), asset_type, None
681+
)
682+
}
683+
if invalid_types:
673684
raise ErrorCode.INVALID_PARAMETER_VALUE.exception_with_parameters(
674-
asset_types, "applicable_asset_types", _complete_type_list
685+
invalid_types, "applicable_asset_types", "SDK asset types"
675686
)
676687
self.options.applicable_asset_types = json.dumps(list(asset_types))
677688

@@ -826,7 +837,7 @@ def create(
826837
multi_valued: bool = False,
827838
options_name: Optional[str] = None,
828839
applicable_connections: Optional[Set[str]] = None,
829-
applicable_asset_types: Optional[AssetTypes] = None,
840+
applicable_asset_types: Optional[Union[Set[str], AssetTypes]] = None,
830841
applicable_glossaries: Optional[Set[str]] = None,
831842
applicable_glossary_types: Optional[GlossaryTypes] = None,
832843
applicable_other_asset_types: Optional[OtherAssetTypes] = None,

tests/unit/constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@
699699
(
700700
APPLICABLE_ASSET_TYPES,
701701
{"Bogus"},
702-
"ATLAN-PYTHON-400-051 {'Bogus'} is an invalid value for applicable_asset_types should be in ",
702+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_asset_types'.",
703703
),
704704
(
705705
APPLICABLE_GLOSSARY_TYPES,
@@ -709,7 +709,7 @@
709709
(
710710
APPLICABLE_GLOSSARY_TYPES,
711711
{"Bogus"},
712-
"ATLAN-PYTHON-400-051 {'Bogus'} is an invalid value for applicable_glossary_types should be in ",
712+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_glossary_types'.",
713713
),
714714
(
715715
APPLICABLE_DOMAIN_TYPES,
@@ -719,7 +719,7 @@
719719
(
720720
APPLICABLE_DOMAIN_TYPES,
721721
{"Bogus"},
722-
"ATLAN-PYTHON-400-051 {'Bogus'} is an invalid value for applicable_domain_types should be in ",
722+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_domain_types'.",
723723
),
724724
(
725725
APPLICABLE_OTHER_ASSET_TYPES,
@@ -729,7 +729,7 @@
729729
(
730730
APPLICABLE_OTHER_ASSET_TYPES,
731731
{"Bogus"},
732-
"ATLAN-PYTHON-400-051 {'Bogus'} is an invalid value for applicable_other_asset_types should be in ",
732+
"ATLAN-PYTHON-400-051 Invalid value(s) {'Bogus'} provided for 'applicable_other_asset_types'.",
733733
),
734734
(
735735
APPLICABLE_ENTITY_TYPES,

0 commit comments

Comments
 (0)