Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli/properties): fix data type validation #12170

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
PropertyValueClass,
StructuredPropertyDefinitionClass,
)
from datahub.metadata.urns import StructuredPropertyUrn, Urn
from datahub.metadata.urns import DataTypeUrn, StructuredPropertyUrn, Urn
from datahub.utilities.urns._urn_base import URN_TYPES

logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -86,19 +86,31 @@ class StructuredProperties(ConfigModel):

@validator("type")
def validate_type(cls, v: str) -> str:
# Convert to lowercase if needed
if not v.islower():
# This logic is somewhat hacky, since we need to deal with
# 1. fully qualified urns
# 2. raw data types, that need to get the datahub namespace prefix
# While keeping the user-facing interface and error messages clean.

if not v.startswith("urn:li:") and not v.islower():
# Convert to lowercase if needed
v = v.lower()
logger.warning(
f"Structured property type should be lowercase. Updated to {v.lower()}"
f"Structured property type should be lowercase. Updated to {v}"
)
v = v.lower()

urn = Urn.make_data_type_urn(v)

# Check if type is allowed
if not AllowedTypes.check_allowed_type(v):
data_type_urn = DataTypeUrn.from_string(urn)
unqualified_data_type = data_type_urn.id
if unqualified_data_type.startswith("datahub."):
unqualified_data_type = unqualified_data_type[len("datahub.") :]
if not AllowedTypes.check_allowed_type(unqualified_data_type):
raise ValueError(
f"Type {v} is not allowed. Allowed types are {AllowedTypes.values()}"
f"Type {unqualified_data_type} is not allowed. Allowed types are {AllowedTypes.values()}"
)
return v

return urn

@property
def fqn(self) -> str:
Expand Down
Loading