Skip to content

Remove pydantic v1 runtime compat shims and update dependencies#3027

Merged
koxudaxi merged 2 commits intomainfrom
pr3-remove-compat-shims
Mar 8, 2026
Merged

Remove pydantic v1 runtime compat shims and update dependencies#3027
koxudaxi merged 2 commits intomainfrom
pr3-remove-compat-shims

Conversation

@koxudaxi
Copy link
Copy Markdown
Owner

@koxudaxi koxudaxi commented Mar 5, 2026

Summary by CodeRabbit

  • Chores
    • Updated Pydantic dependency to conditional v2 specs for different Python versions (targets Pydantic v2 series).
    • Removed the packaging dependency.
    • Dropped legacy multi-version Pydantic compatibility and runtime patching logic; library now standardizes on a v2-oriented BaseModel with relaxed config and simplified YAML/TOML loading.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

The PR removes Pydantic v1 compatibility and related runtime patches, updates dependencies to require Pydantic v2 with Python-version conditionals, and deletes a pydantic_patch module while simplifying util.py to always return a v2-style BaseModel (model_config strict=False).

Changes

Cohort / File(s) Summary
Dependency Updates
pyproject.toml
Removed packaging dependency; replaced pydantic>=1.5 with pydantic>=2,<3; python_version<'3.14' and pydantic>=2.12,<3; python_version>='3.14'.
Pydantic Compatibility Layer Removed
src/datamodel_code_generator/pydantic_patch.py
Deleted module that applied a runtime monkey-patch for Pydantic forward reference evaluation on Python 3.12+.
Utility Module Refactor
src/datamodel_code_generator/util.py
Removed multi-version Pydantic detection and compatibility shims (get_pydantic_version, is_pydantic_v2, model_validator/field_validator overloads, ConfigDict proxy); consolidated _get_base_model_class to always construct a v2-style BaseModel with model_config = ConfigDict(strict=False) and cleaned related imports.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

breaking-change-analyzed, breaking-change

Poem

🐰 Hop along the code-paths bright,

I chewed the v1 vines out of sight,
Now v2 hops in, tidy and spry,
Strict=False, we wink an eye,
A carrot patch for builds gone right.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: removing Pydantic v1 compatibility code (pydantic_patch.py, version checks in util.py) and updating dependencies (pyproject.toml).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pr3-remove-compat-shims

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2026

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 5, 2026

Merging this PR will improve performance by 14.54%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 11 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_perf_large_models_pydantic_v2 3.7 s 3.2 s +14.41%
WallTime test_perf_multiple_files_input 3.7 s 3.2 s +14.54%
WallTime test_perf_stripe_style_pydantic_v2 2 s 1.8 s +11.25%
WallTime test_perf_complex_refs 2.2 s 1.9 s +14.05%
WallTime test_perf_openapi_large 3.1 s 2.7 s +13.45%
WallTime test_perf_graphql_style_pydantic_v2 822.2 ms 731.1 ms +12.46%
WallTime test_perf_aws_style_openapi_pydantic_v2 2 s 1.7 s +14.14%
WallTime test_perf_kubernetes_style_pydantic_v2 2.6 s 2.3 s +13.48%
WallTime test_perf_duplicate_names 1,069.5 ms 934.4 ms +14.45%
WallTime test_perf_all_options_enabled 6.7 s 6.1 s +10.2%
WallTime test_perf_deep_nested 6.1 s 5.4 s +12.59%

Comparing pr3-remove-compat-shims (983b94c) with main (bef3fe5)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@koxudaxi koxudaxi force-pushed the pr2b-remove-v1-output branch from ca48ae2 to 9859ea5 Compare March 5, 2026 16:41
@koxudaxi koxudaxi force-pushed the pr3-remove-compat-shims branch from a8caef4 to 1209712 Compare March 5, 2026 16:41
@koxudaxi koxudaxi force-pushed the pr2b-remove-v1-output branch from 9859ea5 to ad5f527 Compare March 5, 2026 16:49
@koxudaxi koxudaxi force-pushed the pr3-remove-compat-shims branch from 1209712 to da7debb Compare March 5, 2026 16:49
@koxudaxi koxudaxi force-pushed the pr2b-remove-v1-output branch from ad5f527 to 806a780 Compare March 6, 2026 00:47
@koxudaxi koxudaxi force-pushed the pr3-remove-compat-shims branch from da7debb to 1198ce6 Compare March 6, 2026 00:47
@koxudaxi koxudaxi force-pushed the pr2b-remove-v1-output branch from 806a780 to 6862599 Compare March 6, 2026 01:01
@koxudaxi koxudaxi force-pushed the pr3-remove-compat-shims branch from 1198ce6 to da29b4f Compare March 6, 2026 01:01
@koxudaxi koxudaxi force-pushed the pr2b-remove-v1-output branch from 6862599 to 4f3713e Compare March 6, 2026 01:07
@koxudaxi koxudaxi force-pushed the pr3-remove-compat-shims branch 2 times, most recently from 5ec568d to 8560324 Compare March 8, 2026 08:05
@koxudaxi koxudaxi changed the base branch from pr2b-remove-v1-output to main March 8, 2026 08:05
@koxudaxi koxudaxi force-pushed the pr3-remove-compat-shims branch from 8560324 to 3953c40 Compare March 8, 2026 08:06
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bef3fe5) to head (983b94c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3027   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           86        85    -1     
  Lines        17710     17684   -26     
  Branches      2069      2068    -1     
=========================================
- Hits         17710     17684   -26     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pyproject.toml`:
- Line 38: Update the pydantic dependency constraint in pyproject.toml from
"pydantic>=2" to "pydantic>=2.12,<3" so the project requires the first release
with Python 3.14 support and prevents accidental major-version upgrades; locate
the dependency entry for "pydantic" and replace its version specifier
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8d058047-e493-4ccf-9753-6610da280699

📥 Commits

Reviewing files that changed from the base of the PR and between bef3fe5 and 3953c40.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock, !**/*.lock and included by none
📒 Files selected for processing (3)
  • pyproject.toml
  • src/datamodel_code_generator/pydantic_patch.py
  • src/datamodel_code_generator/util.py
💤 Files with no reviewable changes (1)
  • src/datamodel_code_generator/pydantic_patch.py

Comment thread pyproject.toml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pyproject.toml (1)

31-42: Add packaging to test dependencies explicitly.

Six test files import packaging.version directly, but pyproject.toml does not declare packaging as an explicit dependency. This makes tests reliant on transitive dependencies from black, isort, and other packages, which is fragile. Add packaging to [dependency-groups] test.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pyproject.toml` around lines 31 - 42, The test suite relies on the packaging
library transitively; update the pyproject.toml test dependency group by adding
an explicit entry for packaging (for example "packaging>=23.0,<26" or your
chosen semver) under [dependency-groups] test so tests import packaging.version
directly without relying on transitive deps from black/isort; locate the test
group in pyproject.toml and append the packaging string to the list of test
dependencies.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pyproject.toml`:
- Around line 31-42: The test suite relies on the packaging library
transitively; update the pyproject.toml test dependency group by adding an
explicit entry for packaging (for example "packaging>=23.0,<26" or your chosen
semver) under [dependency-groups] test so tests import packaging.version
directly without relying on transitive deps from black/isort; locate the test
group in pyproject.toml and append the packaging string to the list of test
dependencies.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ab7c5d56-293c-4f02-be54-e28dd773e7a9

📥 Commits

Reviewing files that changed from the base of the PR and between 3953c40 and 983b94c.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock, !**/*.lock and included by none
📒 Files selected for processing (1)
  • pyproject.toml

@koxudaxi koxudaxi merged commit 1cbfbc5 into main Mar 8, 2026
39 checks passed
@koxudaxi koxudaxi deleted the pr3-remove-compat-shims branch March 8, 2026 08:29
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 8, 2026

Breaking Change Analysis

Result: Breaking changes detected

Reasoning: This PR removes pydantic v1 runtime compatibility shims and updates the dependency to require pydantic>=2. The main breaking changes are: (1) Users must have pydantic v2 installed - pydantic v1 is no longer supported at runtime; (2) Internal compatibility utilities like is_pydantic_v2(), model_validator(), field_validator(), and ConfigDict were removed from util.py; (3) The pydantic_patch.py module was deleted; (4) The packaging dependency was removed. These are API changes affecting users who either have pydantic v1 installed or import internal utilities directly.

Content for Release Notes

API/CLI Changes


This analysis was performed by Claude Code Action

@github-actions
Copy link
Copy Markdown
Contributor

🎉 Released in 0.55.0

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant