Migrate from pydantic v1 to v2 API#611
Open
ritchelakwali wants to merge 2 commits intojupyter-server:mainfrom
Open
Migrate from pydantic v1 to v2 API#611ritchelakwali wants to merge 2 commits intojupyter-server:mainfrom
ritchelakwali wants to merge 2 commits intojupyter-server:mainfrom
Conversation
Remove the pydantic_v1 compatibility shim and migrate all code to use native pydantic v2 API. Changes: - Replace all pydantic_v1 shim imports with direct pydantic v2 imports - Migrate @root_validator to @model_validator(mode='before') - Replace class Config: orm_mode=True with model_config=ConfigDict(from_attributes=True) - Replace .dict() with .model_dump(), .json() with .model_dump_json() - Replace .from_orm() with .model_validate() - Add explicit = None defaults to Optional fields (required by pydantic v2) - Add CoercedStr type for backward-compatible int-to-str coercion - Broaden parameters dict value type to accept int/float/bool (previously coerced by v1) - Update pydantic dependency: >=1.10,<3 -> >=2.0,<3 - Delete jupyter_scheduler/pydantic_v1/ shim directory
for more information, see https://pre-commit.ci
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
The
pydantic_v1compatibility shim imports frompydantic.v1, which is deprecated and will be removed in a future pydantic release. On Python 3.14+, the v1 compat layer already throwsConfigErroron import, makingjupyter-schedulerincompatible with newer Python versions.This PR removes the shim entirely and migrates all code to native pydantic v2 API.
Changes
Removed
jupyter_scheduler/pydantic_v1/— the entire v1 compatibility shim (3 files)Updated (9 files)
@root_validator→@model_validator(mode='before')(2 instances)class Config: orm_mode=True→model_config=ConfigDict(from_attributes=True)(4 instances).dict()→.model_dump(),.json()→.model_dump_json()(30+ instances).from_orm()→.model_validate()(11 instances)Optional[X]fields now have explicit= Nonedefaults (required by pydantic v2)CoercedStrtype for backward-compatible int-to-str coercionparametersdict value type to accept int/float/boolpydantic>=1.10,<3→pydantic>=2.0,<3Testing