Skip to content

fix: don't crash on --config-root without --resolve-all-configs#2597

Merged
DanielNoord merged 4 commits into
PyCQA:mainfrom
Gooh456:issue/1990
Jul 25, 2026
Merged

fix: don't crash on --config-root without --resolve-all-configs#2597
DanielNoord merged 4 commits into
PyCQA:mainfrom
Gooh456:issue/1990

Conversation

@Gooh456

@Gooh456 Gooh456 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

yeah this one's just been broken since forever. --config-root on its own throws a raw UnsupportedSettings traceback instead of doing... anything.

Root cause is in main.py: config_root only gets popped out of config_dict inside the if resolve_all_configs: branch. So if you pass --config-root without also passing --resolve-all-configs, it's still sitting in the dict when it gets splatted into Config(**config_dict), and Config has no idea what config_root is, so it errors out.

The help text for the flag literally says it's "used with the --resolve-all-configs flag" - so without that flag it should just be a no-op, not a crash. Fix is to pop it unconditionally, same as resolve_all_configs itself already is a few lines up.

Verified against main: reverted my change locally and reproduced the exact traceback from #1990 (isort.exceptions.UnsupportedSettings: ... - config_root = ..). With the fix it runs fine.

Added a regression test in tests/unit/test_main.py that calls --config-root without --resolve-all-configs and just checks it doesn't blow up.

Fixes #1990

…onfigs

config_root was only popped out of config_dict when resolve_all_configs
was set, so using --config-root on its own left it in the dict that gets
splatted into Config(**config_dict), which blows up with
UnsupportedSettings. The help text for --config-root already says it's
"used with the --resolve-all-configs flag", implying it's just a no-op
otherwise, not a hard error. Pop it unconditionally instead.

Fixes PyCQA#1990

Signed-off-by: Kyue <164024549+Gooh456@users.noreply.github.com>

@DanielNoord DanielNoord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should give a warning (by raising an error) that this config isn't useful without resolve_all_configs. See other examples in the codebase.

Signed-off-by: Kyue <164024549+Gooh456@users.noreply.github.com>
@Gooh456

Gooh456 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

good call. added that, exits with a clear message now instead of the confusing UnsupportedSettings crash. same sys.exit("Error: ...") pattern used a few lines up for the no-paths case. updated the old test to expect the error and added one for config-root + resolve-all-configs together still working.

Comment thread isort/main.py Outdated
allow_root = config_dict.pop("allow_root", None)
resolve_all_configs = config_dict.pop("resolve_all_configs", False)
config_root_given = "config_root" in config_dict
config_root = config_dict.pop("config_root", ".")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can remain on line 1051 now

Signed-off-by: Kyue <164024549+Gooh456@users.noreply.github.com>
@Gooh456

Gooh456 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

yeah good catch, moved it back inline. no reason to hold it in a separate var anymore.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.33%. Comparing base (3d72652) to head (ee9ba80).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2597      +/-   ##
==========================================
+ Coverage   99.30%   99.33%   +0.03%     
==========================================
  Files          41       41              
  Lines        3150     3155       +5     
  Branches      680      682       +2     
==========================================
+ Hits         3128     3134       +6     
  Misses         14       14              
+ Partials        8        7       -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanielNoord
DanielNoord enabled auto-merge July 25, 2026 13:16
@DanielNoord
DanielNoord added this pull request to the merge queue Jul 25, 2026
Merged via the queue into PyCQA:main with commit 3f17477 Jul 25, 2026
26 checks passed
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.

--config-root flag doesn't work

2 participants