Repository: callowayproject/bump-my-version (python)

Issue:
Version bump crashes
* 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}\""
```


Pull request:
Fixed regression in config update.
Fixes #108

Patch:
diff --git a/bumpversion/config/files.py b/bumpversion/config/files.py
index c8287d7a..88d4e99e 100644
--- a/bumpversion/config/files.py
+++ b/bumpversion/config/files.py
@@ -136,7 +136,7 @@ def update_config_file(
         search=config.search,
         replace=config.replace,
         regex=config.regex,
-        ignore_missing_version=config.ignore_missing_version,
+        ignore_missing_version=True,
         serialize=config.serialize,
         parse=config.parse,
     )


Test patch:
diff --git a/tests/test_bump.py b/tests/test_bump.py
index bfd47f05..2e4d080a 100644
--- a/tests/test_bump.py
+++ b/tests/test_bump.py
@@ -1,5 +1,6 @@
 """Tests for the bump module."""
 from pathlib import Path
+from textwrap import dedent
 from unittest.mock import MagicMock, patch
 
 import pytest
@@ -186,3 +187,70 @@ def test_commit_and_tag_with_config_file(mock_context):
     config.scm_info.tool.commit_to_scm.assert_called_once()
     config.scm_info.tool.tag_in_scm.assert_called_once()
     assert set(config.scm_info.tool.commit_to_scm.call_args[0][0]) == {"foo.txt", "bar.txt", "pyproject.toml"}
+
+
+def test_key_path_required_for_toml_change(tmp_path: Path, caplog):
+    """If the key_path is not provided, the toml file should use standard search and replace."""
+    from bumpversion import config
+    from bumpversion.version_part import VersionConfig
+
+    # Arrange
+    config_path = tmp_path / "pyproject.toml"
+    config_path.write_text(
+        dedent(
+            """
+        [project]
+        version = "0.1.26"
+
+        [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}\\""
+        """
+        )
+    )
+
+    conf = config.get_configuration(config_file=config_path)
+
+    # Act
+    from click.testing import CliRunner, Result
+    from bumpversion import cli
+
+    runner: CliRunner = CliRunner()
+    with inside_dir(tmp_path):
+        result: Result = runner.invoke(
+            cli.cli,
+            ["bump", "-vv", "minor"],
+        )
+
+    if result.exit_code != 0:
+        print(caplog.text)
+        print("Here is the output:")
+        print(result.output)
+        import traceback
+
+        print(traceback.print_exception(result.exc_info[1]))
+
+    # Assert
+    assert result.exit_code == 0
+    assert config_path.read_text() == dedent(
+        """
+        [project]
+        version = "0.2.0"
+
+        [tool.bumpversion]
+        current_version = "0.2.0"
+        allow_dirty = true
+        commit = true
+
+        [[tool.bumpversion.files]]
+        filename = "pyproject.toml"
+        search = "version = \\"{current_version}\\""
+        replace = "version = \\"{new_version}\\""
+        """
+    )