Skip to content

Prefer CLI input over pyproject url#3083

Merged
koxudaxi merged 1 commit intomainfrom
fix-3076-cli-input-priority
Apr 14, 2026
Merged

Prefer CLI input over pyproject url#3083
koxudaxi merged 1 commit intomainfrom
fix-3076-cli-input-priority

Conversation

@koxudaxi
Copy link
Copy Markdown
Owner

@koxudaxi koxudaxi commented Apr 14, 2026

Fixes: #3076

Summary by CodeRabbit

  • Bug Fixes
    • Improved input source precedence to ensure CLI-provided arguments correctly override configuration file settings, preventing conflicts from multiple input sources.

@github-actions
Copy link
Copy Markdown
Contributor

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ff98b50d-85a9-4009-b4c3-cddae1b15d6e

📥 Commits

Reviewing files that changed from the base of the PR and between 05901ff and 0e8995f.

📒 Files selected for processing (2)
  • src/datamodel_code_generator/__main__.py
  • tests/main/test_main_general.py

📝 Walkthrough

Walkthrough

The PR addresses a configuration precedence issue where CLI arguments for input sources were ignored when pyproject.toml contained conflicting settings. The implementation now explicitly detects which of input, url, or input_model are provided via CLI and clears the others to ensure proper precedence handling.

Changes

Cohort / File(s) Summary
Configuration Merge Logic
src/datamodel_code_generator/__main__.py
Updated Config.merge_args() to detect CLI-provided input sources (input, url, input_model) and clear competing sources by setting them to None, ensuring CLI arguments take precedence over pyproject.toml settings.
CLI Precedence Tests
tests/main/test_main_general.py
Added two test cases (test_cli_input_overrides_pyproject_url, test_cli_url_overrides_pyproject_input) verifying CLI flags override conflicting pyproject.toml configuration, with mocking to ensure expected calls and output correctness.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

breaking-change-analyzed

Poem

🐰 A rabbit hops through config files with glee,
CLI flags now trump the config tree!
When input arrives from the command so bright,
All other sources fade from sight.

🚥 Pre-merge checks | ✅ 5
✅ 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 reflects the main change: implementing CLI --input precedence over pyproject.toml url setting to address issue #3076.
Linked Issues check ✅ Passed The code changes implement the required fix for #3076: CLI --input now takes precedence over pyproject.toml url setting, with tests verifying both precedence scenarios.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing #3076: Config.merge_args() logic and corresponding tests for CLI input precedence.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-3076-cli-input-priority

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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 14, 2026

Merging this PR will not alter performance

⚠️ 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 untouched benchmarks
⏩ 98 skipped benchmarks1


Comparing fix-3076-cli-input-priority (0e8995f) with main (05901ff)

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3083   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           87        87           
  Lines        18247     18274   +27     
  Branches      2087      2089    +2     
=========================================
+ Hits         18247     18274   +27     
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.

@koxudaxi koxudaxi merged commit f0960e9 into main Apr 14, 2026
38 checks passed
@koxudaxi koxudaxi deleted the fix-3076-cli-input-priority branch April 14, 2026 06:41
@github-actions
Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is a bug fix ensuring CLI input arguments (input, url, input_model) correctly take precedence over pyproject.toml configuration. When one of these fields is explicitly set via CLI, the others are now cleared to prevent conflicts from multiple input sources. This corrects previously broken precedence behavior (issue #3076) rather than changing intended API behavior. No CLI options, Python API signatures, defaults, generated code output, or templates are changed. Users were experiencing the buggy behavior rather than depending on it, so this is not a breaking change.


This analysis was performed by Claude Code Action

@vdusek
Copy link
Copy Markdown

vdusek commented Apr 14, 2026

Hi @koxudaxi, I think this should apply to all fields, not just ("input", "url", "input_model").

In general, users should be able to configure every field either through a configuration file or via CLI arguments, with CLI arguments taking precedence.

@koxudaxi
Copy link
Copy Markdown
Owner Author

@vdusek
Thanks. I agree that CLI options should generally take precedence over config file values.

In this case, though, that already happens for normal fields. The special handling here is only for input, url, and input_model because they are mutually exclusive. Without clearing the other two, values from pyproject.toml can remain and conflict with the CLI input source.

@vdusek
Copy link
Copy Markdown

vdusek commented Apr 16, 2026

@koxudaxi Perfect, thanks for the clarification.

@github-actions
Copy link
Copy Markdown
Contributor

🎉 Released in 0.56.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.

CLI flag --input is ignored when url is set in pyproject.toml

2 participants