callowayproject/bump-my-version

Version bump crashes

Closed this issue · 4 comments

  • 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}\""

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

@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"

@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"

@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.