forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingest): add pydantic helper for removed fields (datahub-project…
- Loading branch information
1 parent
aa6c701
commit 1834749
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
metadata-ingestion/src/datahub/configuration/validate_field_removal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters