Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version bump crashes #108

Closed
rgryta opened this issue Dec 18, 2023 · 4 comments · Fixed by #110
Closed

Version bump crashes #108

rgryta opened this issue Dec 18, 2023 · 4 comments · Fixed by #110
Labels
bug Something isn't working

Comments

@rgryta
Copy link
Contributor

rgryta commented Dec 18, 2023

  • bump-my-version version: 0.15.1
  • Python version: 3.11
  • Operating System: macOS Sonoma

Description

Version bump crashes right before creating a commit and throws a KeyError.

Based on quick check - this issue started to appear since version 0.14.0.

What I Did

bump-my-version bump patch

<click stacktrace>
  File "/.../.virtualenv/.../lib/python3.11/site-packages/bumpversion/cli.py", line 310, in bump
    do_bump(version_part, new_version, config, found_config_file, dry_run)
  File "/.../.virtualenv/.../lib/python3.11/site-packages/bumpversion/bump.py", line 100, in do_bump
    update_config_file(config_file, config, version, next_version, ctx, dry_run)
  File "/.../.virtualenv/.../lib/python3.11/site-packages/bumpversion/config/files.py", line 145, in update_config_file
    updater.update_file(current_version, new_version, context, dry_run)
  File "/.../.virtualenv/.../lib/python3.11/site-packages/bumpversion/files.py", line 307, in update_file
    self._update_toml_file(search_for, raw_search_pattern, replace_with, dry_run)
  File "/.../.virtualenv/.../lib/python3.11/site-packages/bumpversion/files.py", line 322, in _update_toml_file
    raise ValueError(
ValueError: Key 'tool.bumpversion.current_version' in /.../pyproject.toml does not contain the correct contents: 0.1.26
make: *** [bump_patch] Error 1

pyproject.toml configuration (before bump):

[tool.bumpversion]
current_version = "0.1.26"
allow_dirty = true
commit = true

[[tool.bumpversion.files]]
filename = "pyproject.toml"
search = "version = \"{current_version}\""
replace = "version = \"{new_version}\""
@coordt
Copy link
Member

coordt commented Dec 18, 2023

Thanks for reporting this so quickly. I'll focus on it immediately

@coordt coordt added the bug Something isn't working label Dec 18, 2023
@coordt
Copy link
Member

coordt commented Dec 18, 2023

@rgryta Just a quick update. As I was looking at what you were doing, I believe it is related to changes on how .toml files are processed. (and obviously you found some unintended consequences.)

I introduced key_path into the file config to allow for more intelligent replacement in structured data files.

While I update the documentation and fix incompatibility with old search/replace methods in toml files... Try this:

[tool.bumpversion]
current_version = "0.1.26"
allow_dirty = true
commit = true

[[tool.bumpversion.files]]
filename = "pyproject.toml"
key_path = "<path.to>.version"

An example for standard pyproject.toml version: key_path = "project.version"

Or for poetry: key_path = "tool.poetry.version"

coordt added a commit that referenced this issue Dec 18, 2023
@coordt coordt linked a pull request Dec 18, 2023 that will close this issue
@proc-2
Copy link

proc-2 commented Dec 22, 2023

@rgryta Just a quick update. As I was looking at what you were doing, I believe it is related to changes on how .toml files are processed. (and obviously you found some unintended consequences.)

I introduced key_path into the file config to allow for more intelligent replacement in structured data files.

While I update the documentation and fix incompatibility with old search/replace methods in toml files... Try this:

[tool.bumpversion]
current_version = "0.1.26"
allow_dirty = true
commit = true

[[tool.bumpversion.files]]
filename = "pyproject.toml"
key_path = "<path.to>.version"

An example for standard pyproject.toml version: key_path = "project.version"

Or for poetry: key_path = "tool.poetry.version"

I was having the same issue as @rgryta on v0.15.3 (at least in dry run mode, haven't tried to use it for real yet). I tried key_path but it does not seem to prevent the search-and-replace of pyproject.toml from modifying tool.bumpversion.current_version (when the intention is to update tool.poetry.version). Here is what I tried:

[[tool.bumpversion.files]]
filename = "pyproject.toml"
key_path = "tool.poetry.version"

@coordt
Copy link
Member

coordt commented Dec 23, 2023

@proc-2 Can you verify that you are using 0.15.3?

I'm asking because I have a specific test for this issue.

The real issue is that the generic search for version = "{current_version" matches both the line starting with version and bumpversion's own current_version. Prior to the fix, when bump-my-version tries to update its own configuration it detects the value is different than expected, and explodes.

If you are really using 0.15.3, I'll need more information to be able to reproduce (and re-open) this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants