Skip to content

Commit 4392d72

Browse files
authored
fix(cli/properties): fix data type validation (#12170)
1 parent da8f822 commit 4392d72

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

metadata-ingestion/src/datahub/api/entities/structuredproperties/structuredproperties.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
PropertyValueClass,
1515
StructuredPropertyDefinitionClass,
1616
)
17-
from datahub.metadata.urns import StructuredPropertyUrn, Urn
17+
from datahub.metadata.urns import DataTypeUrn, StructuredPropertyUrn, Urn
1818
from datahub.utilities.urns._urn_base import URN_TYPES
1919

2020
logging.basicConfig(level=logging.INFO)
@@ -86,19 +86,31 @@ class StructuredProperties(ConfigModel):
8686

8787
@validator("type")
8888
def validate_type(cls, v: str) -> str:
89-
# Convert to lowercase if needed
90-
if not v.islower():
89+
# This logic is somewhat hacky, since we need to deal with
90+
# 1. fully qualified urns
91+
# 2. raw data types, that need to get the datahub namespace prefix
92+
# While keeping the user-facing interface and error messages clean.
93+
94+
if not v.startswith("urn:li:") and not v.islower():
95+
# Convert to lowercase if needed
96+
v = v.lower()
9197
logger.warning(
92-
f"Structured property type should be lowercase. Updated to {v.lower()}"
98+
f"Structured property type should be lowercase. Updated to {v}"
9399
)
94-
v = v.lower()
100+
101+
urn = Urn.make_data_type_urn(v)
95102

96103
# Check if type is allowed
97-
if not AllowedTypes.check_allowed_type(v):
104+
data_type_urn = DataTypeUrn.from_string(urn)
105+
unqualified_data_type = data_type_urn.id
106+
if unqualified_data_type.startswith("datahub."):
107+
unqualified_data_type = unqualified_data_type[len("datahub.") :]
108+
if not AllowedTypes.check_allowed_type(unqualified_data_type):
98109
raise ValueError(
99-
f"Type {v} is not allowed. Allowed types are {AllowedTypes.values()}"
110+
f"Type {unqualified_data_type} is not allowed. Allowed types are {AllowedTypes.values()}"
100111
)
101-
return v
112+
113+
return urn
102114

103115
@property
104116
def fqn(self) -> str:

0 commit comments

Comments
 (0)