MINOR: Fix pydantic warnings in ingestion (#20822)

* MINOR: Fix pydantic warnings in ingestion

* pydantic fix
This commit is contained in:
Mayur Singal 2025-04-15 10:29:05 +05:30 committed by GitHub
parent b14f83940a
commit 56d3c335a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,6 +46,29 @@ class BaseModel(PydanticBaseModel):
Specified as `--base-class BASE_CLASS` in the generator.
"""
def model_post_init(self, context: Any, /):
"""
This function is used to parse the FilterPattern fields for the Connection classes.
This is needed because dict is defined in the JSON schema for the FilterPattern field,
but a FilterPattern object is required in the generated code.
"""
# pylint: disable=import-outside-toplevel
try:
if not self.__class__.__name__.endswith("Connection"):
# Only parse FilterPattern for Connection classes
return
for field in self.__pydantic_fields__:
if field.endswith("FilterPattern"):
from metadata.generated.schema.type.filterPattern import (
FilterPattern,
)
value = getattr(self, field)
if isinstance(value, dict):
setattr(self, field, FilterPattern(**value))
except Exception as exc:
logger.warning(f"Exception while parsing FilterPattern: {exc}")
@model_validator(mode="after")
@classmethod
def parse_name(cls, values): # pylint: disable=inconsistent-return-statements
@ -70,7 +93,7 @@ class BaseModel(PydanticBaseModel):
raise exc
return values
def model_dump_json( # pylint: disable=too-many-arguments,unused-argument
def model_dump_json( # pylint: disable=too-many-arguments
self,
*,
mask_secrets: Optional[bool] = None,