Skip to content

Add deprecation warning for default output-model-type#2910

Merged
koxudaxi merged 1 commit intomainfrom
deprecate-default-output-model-type
Jan 3, 2026
Merged

Add deprecation warning for default output-model-type#2910
koxudaxi merged 1 commit intomainfrom
deprecate-default-output-model-type

Conversation

@koxudaxi
Copy link
Copy Markdown
Owner

@koxudaxi koxudaxi commented Jan 3, 2026

Fixes: #2466

Summary by CodeRabbit

  • Chores
    • Added deprecation warning when output model type is not explicitly specified in configuration, encouraging users to explicitly set this option. Test suite updated to handle this new warning appropriately.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 3, 2026

📝 Walkthrough

Walkthrough

The changes add a deprecation warning that alerts users when they don't explicitly specify the --output-model-type flag, informing them that the implicit Pydantic v1 default is deprecated. A pytest filter is simultaneously added to suppress this warning during test execution.

Changes

Cohort / File(s) Summary
Configuration & Testing
pyproject.toml
Added pytest filterwarnings entry to suppress "No --output-model-type specified" deprecation warning during test runs
Deprecation Warning
src/datamodel_code_generator/__main__.py
Added conditional deprecation warning in main() that triggers when no explicit --output-model-type is provided and the effective default resolves to DataModelType.PydanticBaseModel, informing users to specify the flag explicitly

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hops with glee at clarity's call!
No more silent defaults for all,
Speak up, dear user, choose thy way,
Pydantic's version here to stay! 🎯

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding a deprecation warning for the default output-model-type option.
Linked Issues check ✅ Passed The PR implements a deprecation warning as an intermediate step toward issue #2466's goal of removing the default output-model-type, warning users when no explicit type is provided.
Out of Scope Changes check ✅ Passed All changes are directly related to the deprecation warning objective: pytest filter configuration and deprecation warning logic in the main module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dcc5567 and 30c1d04.

📒 Files selected for processing (2)
  • pyproject.toml
  • src/datamodel_code_generator/__main__.py
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: koxudaxi
Repo: koxudaxi/datamodel-code-generator PR: 2799
File: src/datamodel_code_generator/util.py:49-66
Timestamp: 2025-12-25T09:23:08.506Z
Learning: In datamodel-code-generator, the is_pydantic_v2() and is_pydantic_v2_11() functions in src/datamodel_code_generator/util.py intentionally use global variable caching (_is_v2, _is_v2_11) on top of lru_cache for performance optimization. This dual-layer caching eliminates function call overhead and cache lookup overhead for frequently-called version checks. The PLW0603 linter warnings should be suppressed with # noqa: PLW0603 as this is a deliberate design choice.
Learnt from: koxudaxi
Repo: koxudaxi/datamodel-code-generator PR: 2890
File: tests/data/expected/main/jsonschema/ref_nullable_with_constraint.py:14-15
Timestamp: 2026-01-02T08:25:19.839Z
Learning: The datamodel-code-generator currently generates RootModel subclasses with an explicit `root` field annotation (e.g., `class StringType(RootModel[str]): root: str`). This is existing behavior of the code generator and should not be flagged as an issue introduced by new changes.
📚 Learning: 2026-01-02T08:25:19.839Z
Learnt from: koxudaxi
Repo: koxudaxi/datamodel-code-generator PR: 2890
File: tests/data/expected/main/jsonschema/ref_nullable_with_constraint.py:14-15
Timestamp: 2026-01-02T08:25:19.839Z
Learning: The datamodel-code-generator currently generates RootModel subclasses with an explicit `root` field annotation (e.g., `class StringType(RootModel[str]): root: str`). This is existing behavior of the code generator and should not be flagged as an issue introduced by new changes.

Applied to files:

  • src/datamodel_code_generator/__main__.py
📚 Learning: 2025-12-25T09:23:08.506Z
Learnt from: koxudaxi
Repo: koxudaxi/datamodel-code-generator PR: 2799
File: src/datamodel_code_generator/util.py:49-66
Timestamp: 2025-12-25T09:23:08.506Z
Learning: In datamodel-code-generator, the is_pydantic_v2() and is_pydantic_v2_11() functions in src/datamodel_code_generator/util.py intentionally use global variable caching (_is_v2, _is_v2_11) on top of lru_cache for performance optimization. This dual-layer caching eliminates function call overhead and cache lookup overhead for frequently-called version checks. The PLW0603 linter warnings should be suppressed with # noqa: PLW0603 as this is a deliberate design choice.

Applied to files:

  • src/datamodel_code_generator/__main__.py
🧬 Code graph analysis (1)
src/datamodel_code_generator/__main__.py (1)
src/datamodel_code_generator/enums.py (1)
  • DataModelType (48-56)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Analyze (python)
  • GitHub Check: 3.14 on Windows
  • GitHub Check: 3.11 on macOS
  • GitHub Check: 3.13 on Windows
  • GitHub Check: benchmarks
  • GitHub Check: 3.12 on Windows
  • GitHub Check: 3.10 on Windows
  • GitHub Check: 3.11 on Windows
  • GitHub Check: 3.12 on macOS
  • GitHub Check: 3.13 on macOS
🔇 Additional comments (2)
pyproject.toml (1)

216-216: LGTM! Test filter correctly suppresses the new deprecation warning.

The PyTest filter appropriately suppresses the deprecation warning during test execution, preventing test output pollution while still allowing real users to see the warning.

src/datamodel_code_generator/__main__.py (1)

1196-1210: LGTM! Deprecation warning logic is correctly implemented.

The warning correctly identifies when the implicit default PydanticBaseModel is being used versus explicitly specified. The three-part condition ensures:

  1. No CLI argument was provided (namespace.output_model_type is None)
  2. No pyproject.toml configuration was set (pyproject_config.get("output_model_type") is None)
  3. The effective config uses the default (config.output_model_type == DataModelType.PydanticBaseModel)

The message is clear, actionable, and includes an example plus a link to the tracking issue. Placement after config.merge_args() ensures all configuration sources have been merged, and respecting --disable-warnings is appropriate.


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 Jan 3, 2026

📚 Docs Preview: https://pr-2910.datamodel-code-generator.pages.dev

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jan 3, 2026

CodSpeed Performance Report

Merging #2910 will not alter performance

Comparing deprecate-default-output-model-type (30c1d04) with main (dcc5567)

⚠️ 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.

Summary

✅ 11 untouched
⏩ 98 skipped1

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.40%. Comparing base (dcc5567) to head (30c1d04).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2910   +/-   ##
=======================================
  Coverage   99.40%   99.40%           
=======================================
  Files          95       95           
  Lines       16903    16905    +2     
  Branches     1989     1990    +1     
=======================================
+ Hits        16802    16804    +2     
  Misses         52       52           
  Partials       49       49           
Flag Coverage Δ
unittests 99.40% <100.00%> (+<0.01%) ⬆️

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.

@koxudaxi koxudaxi merged commit f2859a6 into main Jan 3, 2026
39 checks passed
@koxudaxi koxudaxi deleted the deprecate-default-output-model-type branch January 3, 2026 05:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 3, 2026

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR adds a deprecation warning when --output-model-type is not explicitly specified and defaults to pydantic.BaseModel (Pydantic v1). The warning is purely informational and does not change any behavior, generated code, CLI options, or defaults. Deprecation warnings are not breaking changes - they inform users about future changes but don't require immediate action. Users who already explicitly specify --output-model-type (via CLI or config) won't see any warning. The generated code remains identical whether the warning is shown or not.


This analysis was performed by Claude Code Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 3, 2026

🎉 Released in 0.52.1

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.

Remove default value for --output-model-type

1 participant