From 18347492e98a11195e1ad8e63fb7eb0b95d19e7c Mon Sep 17 00:00:00 2001 From: Harshal Sheth Date: Mon, 26 Dec 2022 05:01:49 -0500 Subject: [PATCH] feat(ingest): add pydantic helper for removed fields (#6853) --- .../configuration/validate_field_removal.py | 22 +++++++++++++++++++ .../ingestion/source/looker/looker_source.py | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 metadata-ingestion/src/datahub/configuration/validate_field_removal.py diff --git a/metadata-ingestion/src/datahub/configuration/validate_field_removal.py b/metadata-ingestion/src/datahub/configuration/validate_field_removal.py new file mode 100644 index 00000000000000..f3b45e71ddb856 --- /dev/null +++ b/metadata-ingestion/src/datahub/configuration/validate_field_removal.py @@ -0,0 +1,22 @@ +import warnings +from typing import Type + +import pydantic + + +def pydantic_removed_field( + field: str, + print_warning: bool = True, +) -> classmethod: + def _validate_field_rename(cls: Type, values: dict) -> dict: + if field in values: + if print_warning: + warnings.warn( + f"The {field} was removed, please remove it from your recipe.", + UserWarning, + stacklevel=2, + ) + values.pop(field) + return values + + return pydantic.root_validator(pre=True, allow_reuse=True)(_validate_field_rename) diff --git a/metadata-ingestion/src/datahub/ingestion/source/looker/looker_source.py b/metadata-ingestion/src/datahub/ingestion/source/looker/looker_source.py index d2a077c2a9b774..e98d25c610ad60 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/looker/looker_source.py +++ b/metadata-ingestion/src/datahub/ingestion/source/looker/looker_source.py @@ -24,6 +24,7 @@ import datahub.emitter.mce_builder as builder from datahub.configuration.common import AllowDenyPattern, ConfigurationError +from datahub.configuration.validate_field_removal import pydantic_removed_field from datahub.emitter.mcp import MetadataChangeProposalWrapper from datahub.ingestion.api.common import PipelineContext from datahub.ingestion.api.decorators import ( @@ -102,6 +103,8 @@ class LookerDashboardSourceConfig( LookerAPIConfig, LookerCommonConfig, StatefulIngestionConfigBase ): + _removed_github_info = pydantic_removed_field("github_info") + dashboard_pattern: AllowDenyPattern = Field( AllowDenyPattern.allow_all(), description="Patterns for selecting dashboard ids that are to be included",