Skip to content

Version-less search & replace raise KeyError: 'new_version' exception #70

Closed
@kdeldycke

Description

@kdeldycke
  • bump-my-version version: 0.10.0
  • Python version: 3.11.15
  • Operating System: macOS

Description

A simple search and replace in non-regex mode is ending up raising an error.

What I Did

$ bump-my-version replace --dry-run --verbose --no-configured-files --allow-dirty --ignore-missing-version --search "profanity" --replace "" ./changelog.md
Starting BumpVersion 0.10.0                                                                                                                                                                                         
Parsing version '2.18.0' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'                                                                                                                              
Parsed the following values: major=2, minor=18, patch=0                                                                                                                                                             
Asserting files ./changelog.md contain the version string...                                                                                                                                                        
Found 're.compile('2\\.18\\.0')' in ./changelog.md at line 3: 2.18.0                                                                                                                                                
Traceback (most recent call last):
  File "/Users/kde/.local/bin/bump-my-version", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File ".../site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/rich_click/rich_group.py", line 21, in main
    rv = super().main(*args, standalone_mode=False, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File ".../site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/bumpversion/cli.py", line 517, in replace
    modify_files(configured_files, version, next_version, ctx, dry_run)
  File ".../site-packages/bumpversion/files.py", line 214, in modify_files
    f.replace_version(current_version, new_version, context, dry_run)
  File ".../site-packages/bumpversion/files.py", line 119, in replace_version
    replace_with = self.version_config.replace.format(**context)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'new_version'

As you can see in the verbose logs, bump-my-version is trying to locate the 2\\.18\\.0 version regexp. Which is surprising to me as I was not expecting it to handle versions at all. Instead, I am expecting it to search for the profanity string and replace it with an empty string.

Note that I am performing this from a project, whose pyproject.toml contains:

[tool.bumpversion]
current_version = "2.19.0"
allow_dirty = true
no_regex = true

[[tool.bumpversion.files]]
filename = "./changelog.md"
no_regex = true
search = "## [{current_version} (unreleased)]("
replace = "## [{new_version} (unreleased)]("

But its content has no influence, as deleting it still produce the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions