Skip to content

fix(source add): report an invalid --priority instead of failing with KeyError - #11175

Merged
radoering merged 1 commit into
python-poetry:mainfrom
simpleqt:fix/source-add-invalid-priority
Oct 28, 2026
Merged

radoering merged 1 commit into
python-poetry:mainfrom
simpleqt:fix/source-add-invalid-priority

Conversation

@simpleqt

Copy link
Copy Markdown
Contributor
  • Added tests for changed code.
  • Updated documentation for changed code.

Resolves #11174.

poetry source add looks the --priority value up in the Priority enum (src/poetry/console/commands/source/add.py), so an unknown value raises a KeyError that Cleo prints as the bare string:

$ poetry source add foo https://example.org/simple/ --priority bogus
'BOGUS'

Exit code 1, with no hint about the valid values, although the command's own --help lists them and its other two failure paths (Source with name ... already exists, Source ... is not a valid URL) report themselves in plain language.

The lookup is now wrapped and reports the same kind of message as the neighbouring error paths:

$ poetry source add foo https://example.org/simple/ --priority bogus
Invalid priority 'bogus'. Must be one of: primary, supplemental, explicit.

--priority=Supplemental still works, since the value is upper-cased before the lookup, and the valid values are listed from the enum so the message cannot drift from the accepted set.

tests/console/commands/source/test_add.py::test_source_add_error_invalid_priority fails on the current tree with KeyError: 'BOGUS' and passes with the change; the file is 15 passed. ruff check, ruff format --check and mypy are clean on the changed file. The integration tests were not run here.

Prepared with AI assistance (DeepSeek Harness, dsv41 agent); every line was verified by running the cases above.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 13:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@radoering
radoering force-pushed the fix/source-add-invalid-priority branch from eff0dc2 to e6f8ff5 Compare October 28, 2026 03:56
@radoering
radoering enabled auto-merge (squash) October 28, 2026 03:57
@radoering
radoering merged commit d59ff3b into python-poetry:main Oct 28, 2026
97 of 102 checks passed
radoering pushed a commit that referenced this pull request Nov 21, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

poetry source add --priority <invalid> fails with a bare KeyError instead of a validation message

3 participants