-
Notifications
You must be signed in to change notification settings - Fork 3.3k
refactor(pydantic): remove Pydantic v1 legacy code and migrate fully to v2 #15261
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
base: master
Are you sure you want to change the base?
Conversation
|
🔴 Meticulous spotted visual differences in 2 of 939 screens tested: view and approve differences detected. Meticulous evaluated ~8 hours of user flows against your PR. Last updated for commit 30532e7. This comment will update as new commits are pushed. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
f906c45 to
9a68796
Compare
|
|
||
| class InOperator(v1_ConfigModel): | ||
| class InOperator(BaseModel): | ||
| model_config = {"extra": "forbid"} |
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.
Is there any reason we are not using a v2 ConfigModel where we set extra forbiddens by default, and all the models inherit it?
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.
really good catch
addressed in commit 3a360ce
| model_config = {"extra": "forbid"} | ||
|
|
||
| type: Literal["count", "percentage"] = Field(default="count") | ||
| value: int = Field(default=0) |
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.
I know it is not part of this pr, but at line 42 the comparison is not correct ->
It is comparing self.type (which is a string at runtime) to Literal["count"] (which is a type annotation, not a value). This comparison will always be False.
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.
| ) | ||
|
|
||
|
|
||
| class SqlMetricAssertion(BaseEntityAssertion): |
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.
Shouldn't we explicity specify it implements BaseAssertionProtocol which makes explicit to implement get_id?
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.
The problem is BaseAssertionProtocol is not being used at all in the model hierarchy. Not before the PR and so not now.
- Migrate ConfigModel from Pydantic v1 style (class Config) to v2 style (model_config = ConfigDict)
- Replace 35 instances of manual 'model_config = {"extra": "forbid"}' with ConfigModel inheritance across 9 files
- Simplify Filter union in search_filters.py by removing TYPE_CHECKING conditional
- Fix redshift.py to use parse_obj_allow_extras() instead of direct Config.extra manipulation
This eliminates code duplication and centralizes Pydantic configuration policy.
Bundle ReportChanges will increase total bundle size by 31 bytes (0.0%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: datahub-react-web-esmAssets Changed:
|
This commit completes the migration of all Pydantic v1 legacy syntax to v2 across the entire DataHub Python codebase. **Configuration Migration (18 instances):** - Migrate `class Config:` → `model_config = ConfigDict(...)` - Updated ConfigModel, PermissiveConfigModel, ConnectionModel base classes - Migrated 13 additional model classes across multiple files **Method Migrations (76 instances):** - `.parse_obj()` → `.model_validate()` (38 instances) - `.parse_raw()` → `.model_validate_json()` (2 instances) - `.dict()` → `.model_dump()` (27 instances) - `.json()` → `.model_dump_json()` (4 instances) - `.update_forward_refs()` → `.model_rebuild()` (3 instances) - `.copy()` and `.schema()` - all false positives (dicts/lists/HTTP responses) **Scope of Changes:** - metadata-ingestion/src: 50 instances - metadata-ingestion/tests: 30 instances - datahub-actions: 12 instances - smoke-test: 2 instances **Total: 94 Pydantic v1 calls migrated** **Key Files Updated:** - common.py: Base ConfigModel classes - Multiple source files: sql_queries.py, datahub_classifier.py, schema_assertion.py, etc. - Multiple CLI files: structuredproperties_cli.py, forms_cli.py, dataset_cli.py, etc. - Test files: RDS IAM tests, Unity Catalog tests, assertion tests, etc. - datahub-actions: propagation_action.py, filter tests, consumer offsets - smoke-test: stateful ingestion tests All Pydantic v2 deprecation warnings have been resolved. The codebase is now fully compliant with Pydantic v2 with no remaining v1 syntax.
e08616b to
30532e7
Compare
Context
This PR removes all Pydantic v1 compatibility code and completes the migration to Pydantic v2. This is now safe because:
metadata-ingestion:pydantic>=2.4.0,<3.0.0datahub-actions:pydantic>=2.0.0,<3.0.0smoke-test: uses metadata-ingestion (Pydantic v2)What Changed
Deleted compatibility layer files:
metadata-ingestion/src/datahub/configuration/pydantic_migration_helpers.py(provided v1_* aliases)metadata-ingestion/src/datahub/pydantic/compat.py(version detection utilities)Migrated to native Pydantic v2 APIs (38 files):
v1_ConfigModel→BaseModelv1_Field→Fieldv1_validator→@field_validatorv1_root_validator→@model_validatorExtra.forbid→model_config = {"extra": "forbid"}__fields__→model_fieldsparse_obj()→model_validate()_init_private_attributes→model_post_initRemoved all version checks:
PYDANTIC_VERSION,PYDANTIC_VERSION_2,PYDANTIC_SUPPORTS_CALLABLE_DISCRIMINATORUpdated discriminated unions:
Discriminator/Tag(Pydantic 2.4+) to maintain compatibility with Pydantic 2.0-2.3 used in some Airflow constraint filesUpdated configurations:
pydantic.v1.mypyfrom mypy pluginsBreaking Changes
None for users - all projects already require Pydantic v2. This only affects:
Testing
Files Changed
38 files changed: +1132 insertions, -1386 deletions (net reduction of 254 lines)
Key areas: