Repository navigation
fix(version): report when a project has no version to update - #11296
Open
dongyikuan919 wants to merge 2 commits into
Open
dongyikuan919 wants to merge 2 commits into
dongyikuan919 wants to merge 2 commits into
Conversation
Linked issuesChecked at commit c55f27b #11295 `poetry version` reports a successful bump for a versionless non-package project · 2 of 2 met
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/poetry/console/commands/version.py" line_range="78-84" />
<code_context>
self.poetry.package.pretty_version, version, self.option("next-phase")
)
- if self.option("short"):
- self.line(version.to_string())
- else:
- self.line(
- f"Bumping version from <b>{self.poetry.package.pretty_version}</>"
- f" to <fg=green>{version}</>"
- )
-
if not self.option("dry-run"):
</code_context>
<issue_to_address>
**Committed bumps can look failed**
When stdout is closed or fails after the file write succeeds, `file.write` has persisted the new version before `self.line` writes to a closed or failing stdout and raises, so the caller sees a failed invocation despite the changed file. If the caller retries a `patch` bump, it applies the bump to the new version and skips a release.
Prevent a post-write output failure from being reported as an unsuccessful update, or otherwise ensure retrying the command cannot apply the bump twice.
</issue_to_address>
### Comment 2
<location path="src/poetry/console/commands/version.py" line_range="64" />
<code_context>
content = self.poetry.file.read()
project_content = content.get("project", {})
+ poetry_content = content.get("tool", {}).get("poetry", {})
+ if "version" not in project_content and "version" not in poetry_content:
+ self.line_error(
+ "<error>Cannot update the version because pyproject.toml "
</code_context>
<issue_to_address>
**Versionless dry runs report success**
When the project has neither `project.version` nor `tool.poetry.version` and `--dry-run` is supplied, `handle()` skips the missing-version guard, prints the calculated bump and returns success, so callers see a successful update despite no version field to update.
Run the missing-version guard for dry runs as well as real updates.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: src/poetry/console/commands/version.py:84, src/poetry/console/commands/version.py:64
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Check List
Resolves: #11295
Summary
When neither TOML table declares a version, the version command now reports the missing declaration and exits 1 before printing a bump. Real and dry-run updates use the same check. For a declared version, the command retains its existing output-before-write order so a write to a closed stdout cannot change
pyproject.toml.Evidence
--short, and--dry-runupdate paths exit 1, write no success output, and leavepyproject.tomlbyte-for-byte unchanged.tests/consolewith the test virtualenv onPATHand the network marker excluded had 1,013 passed and 6 skipped.git diff --checkpassed.OpenAI Codex assisted with reproduction, implementation, and testing.