-
Couldn't load subscription status.
- Fork 3.3k
chore: Remove Pydantic V1 deprecation warnings #15057
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
Open
sgomezvillamor
wants to merge
20
commits into
master
Choose a base branch
from
chore-pydantic-warnings
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6d0d821
chore: remove some pydantic v1 deprecations
sgomezvillamor e48ee8a
Merge branch 'master' into chore-pydantic-warnings
sgomezvillamor 02d206f
parse_obj_allow_extras doc
sgomezvillamor 2152966
Merge branch 'chore-pydantic-warnings' of github.com:datahub-project/…
sgomezvillamor aa3dbe7
more
sgomezvillamor 0a114f9
Merge branch 'master' into chore-pydantic-warnings
sgomezvillamor 7738015
fix redshift usage tests
sgomezvillamor 3495079
Merge branch 'chore-pydantic-warnings' of github.com:datahub-project/…
sgomezvillamor 97fedd7
stateful ingestion base
sgomezvillamor 6efc087
Merge branch 'master' into chore-pydantic-warnings
sgomezvillamor 8e7ed0a
fixed more v1 validators
sgomezvillamor cf60287
fixed more v1 validators
sgomezvillamor 6ed6b66
hopefully last batch
sgomezvillamor 4a9e62b
fix up entity dataset
sgomezvillamor 4cad1c1
last batch
sgomezvillamor b50751e
banned apis
sgomezvillamor 61fb2f1
fix up path spec
sgomezvillamor b21864c
Merge branch 'master' into chore-pydantic-warnings
sgomezvillamor c7f1928
fixes after merge master
sgomezvillamor 833b040
Merge branch 'master' into chore-pydantic-warnings
sgomezvillamor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| import pathlib | ||
| from copy import deepcopy | ||
| from typing import Any, Dict, Optional, Union | ||
|
|
||
| from pydantic import Field, FilePath, SecretStr, validator | ||
| from pydantic import ( | ||
| Field, | ||
| FilePath, | ||
| SecretStr, | ||
| field_validator, | ||
| model_validator, | ||
| ) | ||
|
|
||
| from datahub.configuration.common import ConfigModel | ||
| from datahub.configuration.validate_field_rename import pydantic_renamed_field | ||
|
|
@@ -41,7 +48,8 @@ class GitReference(ConfigModel): | |
| transform=lambda url: _GITHUB_URL_TEMPLATE, | ||
| ) | ||
|
|
||
| @validator("repo", pre=True) | ||
| @field_validator("repo", mode="before") | ||
| @classmethod | ||
| def simplify_repo_url(cls, repo: str) -> str: | ||
| if repo.startswith("github.com/") or repo.startswith("gitlab.com"): | ||
| repo = f"https://{repo}" | ||
|
|
@@ -53,21 +61,22 @@ def simplify_repo_url(cls, repo: str) -> str: | |
|
|
||
| return repo | ||
|
|
||
| @validator("url_template", always=True) | ||
| def infer_url_template(cls, url_template: Optional[str], values: dict) -> str: | ||
| if url_template is not None: | ||
| return url_template | ||
| @model_validator(mode="after") | ||
| def infer_url_template(self) -> "GitReference": | ||
| if self.url_template is not None: | ||
| return self | ||
|
|
||
| repo: str = values["repo"] | ||
| if repo.startswith(_GITHUB_PREFIX): | ||
| return _GITHUB_URL_TEMPLATE | ||
| elif repo.startswith(_GITLAB_PREFIX): | ||
| return _GITLAB_URL_TEMPLATE | ||
| if self.repo.startswith(_GITHUB_PREFIX): | ||
| self.url_template = _GITHUB_URL_TEMPLATE | ||
| elif self.repo.startswith(_GITLAB_PREFIX): | ||
| self.url_template = _GITLAB_URL_TEMPLATE | ||
| else: | ||
| raise ValueError( | ||
| "Unable to infer URL template from repo. Please set url_template manually." | ||
| ) | ||
|
|
||
| return self | ||
|
|
||
| def get_url_for_file_path(self, file_path: str) -> str: | ||
| assert self.url_template | ||
| if self.url_subdir: | ||
|
|
@@ -98,35 +107,43 @@ class GitInfo(GitReference): | |
|
|
||
| _fix_deploy_key_newlines = pydantic_multiline_string("deploy_key") | ||
|
|
||
| @validator("deploy_key", pre=True, always=True) | ||
| @model_validator(mode="before") | ||
| @classmethod | ||
| def deploy_key_filled_from_deploy_key_file( | ||
| cls, v: Optional[SecretStr], values: Dict[str, Any] | ||
| ) -> Optional[SecretStr]: | ||
| if v is None: | ||
| cls, values: Dict[str, Any] | ||
| ) -> Dict[str, Any]: | ||
| # In-place update of the input dict would cause state contamination. | ||
| # So a deepcopy is performed first. | ||
| values = deepcopy(values) | ||
|
|
||
| if values.get("deploy_key") is None: | ||
| deploy_key_file = values.get("deploy_key_file") | ||
| if deploy_key_file is not None: | ||
| with open(deploy_key_file) as fp: | ||
| deploy_key = SecretStr(fp.read()) | ||
| return deploy_key | ||
| return v | ||
|
|
||
| @validator("repo_ssh_locator", always=True) | ||
| def infer_repo_ssh_locator( | ||
| cls, repo_ssh_locator: Optional[str], values: dict | ||
| ) -> str: | ||
| if repo_ssh_locator is not None: | ||
| return repo_ssh_locator | ||
|
|
||
| repo: str = values["repo"] | ||
| if repo.startswith(_GITHUB_PREFIX): | ||
| return f"[email protected]:{repo[len(_GITHUB_PREFIX) :]}.git" | ||
| elif repo.startswith(_GITLAB_PREFIX): | ||
| return f"[email protected]:{repo[len(_GITLAB_PREFIX) :]}.git" | ||
| values["deploy_key"] = deploy_key | ||
| return values | ||
|
|
||
| @model_validator(mode="after") | ||
| def infer_repo_ssh_locator(self) -> "GitInfo": | ||
| if self.repo_ssh_locator is not None: | ||
| return self | ||
|
|
||
| if self.repo.startswith(_GITHUB_PREFIX): | ||
| self.repo_ssh_locator = ( | ||
| f"[email protected]:{self.repo[len(_GITHUB_PREFIX) :]}.git" | ||
| ) | ||
| elif self.repo.startswith(_GITLAB_PREFIX): | ||
| self.repo_ssh_locator = ( | ||
| f"[email protected]:{self.repo[len(_GITLAB_PREFIX) :]}.git" | ||
| ) | ||
| else: | ||
| raise ValueError( | ||
| "Unable to infer repo_ssh_locator from repo. Please set repo_ssh_locator manually." | ||
| ) | ||
|
|
||
| return self | ||
|
|
||
| @property | ||
| def branch_for_clone(self) -> Optional[str]: | ||
| # If branch was manually set, we should use it. Otherwise return None. | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dangerous use of assert - low severity
When running Python in production in optimized mode, assert calls are not executed. This mode is enabled by setting the PYTHONOPTIMIZE command line flag. Optimized mode is usually ON in production. Any safety check done using assert will not be executed.
Remediation: Raise an exception instead of using assert.
View details in Aikido Security