Preserve null artpath in edit (#6839)

Fixes #2438.

When editing album metadata, `artpath: null` was converted through the
string parsing path and could become a path ending in `None`.

This keeps YAML null values as `None` when dumping and applying edit
data, and adds a regression test for editing album metadata while
`artpath` is missing.

- Added a regression test.
- Added a changelog entry.
This commit is contained in:
Šarūnas Nejus
2026-07-15 14:35:03 +01:00
committed by GitHub
3 changed files with 24 additions and 0 deletions

View File

@@ -91,6 +91,8 @@ def _safe_value(obj, key, value):
This ensures that values do not change their type when the user edits their
YAML representation.
"""
if value is None:
return True
typ = obj._type(key)
return isinstance(typ, SAFE_TYPES) and isinstance(value, typ.model_type)

View File

@@ -43,6 +43,9 @@ New features
Bug fixes
~~~~~~~~~
- :doc:`plugins/edit`: Preserve missing album art paths when editing album
metadata, instead of turning ``artpath: null`` into a path ending in ``None``.
:bug:`2438`
- :doc:`plugins/subsonicupdate`: Log a clearer error when the Subsonic server
returns a non-JSON response. :bug:`5635`
- :doc:`plugins/missing`: Honor the ``-f``/``--format`` option (and the

View File

@@ -268,6 +268,25 @@ class EditCommandTest(IOMixin, EditMixin, BeetsTestCase):
self.album.items(), self.items_orig, ["albumartist", "mtime"]
)
def test_a_album_edit_preserves_missing_artpath(self, mock_write):
"""Album query (-a), edit album field, preserve missing artpath."""
self.config["edit"]["albumfields"] = "album artpath"
self.run_mocked_command(
{"replacements": {"\u00e4lbum": "modified \u00e4lbum"}},
# Apply changes.
["a"],
args=["-a"],
)
self.album.load()
assert mock_write.call_count == self.TRACK_COUNT
assert self.album.album == "modified \u00e4lbum"
assert self.album.artpath is None
self.assertItemFieldsModified(
self.album.items(), self.items_orig, ["album", "mtime"]
)
def test_malformed_yaml(self, mock_write):
"""Edit the yaml file incorrectly (resulting in a malformed yaml
document)."""