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-less search & replace raise KeyError: 'new_version' exception #70

Closed
kdeldycke opened this issue Sep 15, 2023 · 3 comments · Fixed by #106
Closed

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

kdeldycke opened this issue Sep 15, 2023 · 3 comments · Fixed by #106
Labels
bug Something isn't working

Comments

@kdeldycke
Copy link
Collaborator

kdeldycke commented Sep 15, 2023

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

@kdeldycke
Copy link
Collaborator Author

This issue is still present in 0.12.0:

pyproject.toml:

[tool.bumpversion]
current_version = "2.20.7"
allow_dirty = true

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

changelog.md:

# Changelog

## [2.20.7 (unreleased)](https://github.com/kdeldycke/workflows/compare/v2.20.6...main)

- Test profanity.
$ bump-my-version replace --dry-run --verbose --no-configured-files --allow-dirty --ignore-missing-version --search "profanity" --replace "" ./changelog.md
Starting BumpVersion 0.12.0                                                                                                                                                                                         
Reading config file pyproject.toml:                                                                                                                                                                                 
Parsing version '2.20.7' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'                                                                                                                              
Parsed the following values: major=2, minor=20, patch=7                                                                                                                                                             
Asserting files ./changelog.md contain the version string...                                                                                                                                                        
Found 're.compile('profanity', re.MULTILINE|re.DOTALL)' in ./changelog.md at line 5: profanity                                                                                                                      
Traceback (most recent call last):
  File "/Users/kde/.local/bin/bump-my-version", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/rich_click/rich_command.py", line 126, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/cli.py", line 518, in replace
    modify_files(configured_files, version, next_version, ctx, dry_run)
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/files.py", line 215, in modify_files
    f.replace_version(current_version, new_version, context, dry_run)
  File "/Users/kde/.local/pipx/venvs/bump-my-version/lib/python3.12/site-packages/bumpversion/files.py", line 119, in replace_version
    replace_with = self.version_config.replace.format(**context)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'new_version'

@php-coder
Copy link

+1 here. Any updates on this?

@coordt
Copy link
Member

coordt commented Dec 14, 2023

I'll be on vacation until the end of the year, which will open up my time to focus on clearing up the backlog here.

I appreciate your patience.

@coordt coordt added the bug Something isn't working label Dec 18, 2023
coordt added a commit that referenced this issue Dec 18, 2023
- Added a test for the reported bug
- Fixes #70
@coordt coordt linked a pull request Dec 18, 2023 that will close this issue
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