Skip to content

Migrate from pydantic v1 to v2 API#611

Open
ritchelakwali wants to merge 2 commits intojupyter-server:mainfrom
ritchelakwali:migrate-pydantic-v2
Open

Migrate from pydantic v1 to v2 API#611
ritchelakwali wants to merge 2 commits intojupyter-server:mainfrom
ritchelakwali:migrate-pydantic-v2

Conversation

@ritchelakwali
Copy link

Motivation

The pydantic_v1 compatibility shim imports from pydantic.v1, which is deprecated and will be removed in a future pydantic release. On Python 3.14+, the v1 compat layer already throws ConfigError on import, making jupyter-scheduler incompatible 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=Truemodel_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 = None defaults (required by pydantic v2)
  • Added CoercedStr type for backward-compatible int-to-str coercion
  • Broadened parameters dict value type to accept int/float/bool
  • pydantic>=1.10,<3pydantic>=2.0,<3

Testing

  • 126 tests collected, 124 passed on Python 3.14.0 + pydantic 2.12.5
  • 2 failures are pre-existing Windows path separator issues (unrelated to this PR)

ritchelakwali and others added 2 commits March 11, 2026 11:21
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant