Skip to content

Commit

Permalink
feat(ingest): add pydantic helper for removed fields (datahub-project…
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored and cccs-Dustin committed Feb 1, 2023
1 parent aa6c701 commit 1834749
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1834749

Please sign in to comment.