Skip to content

Commit c7545c8

Browse files
committed
fix bug in comparer + XautoPF match for reference track
1 parent cf0dd15 commit c7545c8

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

docs/info/release-history.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en>`_,
3232
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_
3333

3434

35+
1.1.9
36+
=====
37+
38+
Changed
39+
-----
40+
* :py:class:`.Comparer` now correctly ignores the reference track given when the ``reference_required`` flag is False.
41+
42+
Fixed
43+
-----
44+
* Bug in :py:class:`.XAutoPF` which caused it to always add the tracks that matched the associated tags of
45+
the last played track when the expected values for the condition are null or empty.
46+
47+
3548
1.1.8
3649
=====
3750

musify/processors/compare.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Comparer(DynamicProcessor):
2626
Types of the values in this list are automatically converted to the type of the item field's value.
2727
:param field: The field to match on.
2828
:param reference_required: When True, a reference object of type ``T`` must be passed to the ``compare`` method.
29+
When False, reference files given to the ``compare`` method will be ignored.
2930
An exception will be raised if this is True and reference object is not passed.
3031
"""
3132

@@ -97,13 +98,12 @@ def compare[T: Any](self, item: T, reference: T | None = None) -> bool:
9798
else:
9899
actual = item
99100

100-
if reference is None:
101-
# convert the expected values to the same type as the actual value if not yet converted
101+
if self.reference_required: # use the values from the reference as the expected values
102+
expected = to_collection(reference[tag_name], list)
103+
else: # convert the expected values to the same type as the actual value if not yet converted
102104
if not self._converted:
103105
self._convert_expected(actual)
104106
expected = self.expected
105-
else: # use the values from the reference as the expected values
106-
expected = to_collection(reference[tag_name], list)
107107

108108
if expected: # special on-the-fly conversions for datetime values
109109
if isinstance(actual, datetime) and not isinstance(expected[0], datetime):

tests/processors/test_compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_compare_with_reference(self):
5454
track_1 = random_track()
5555
track_2 = random_track()
5656

57-
comparer = Comparer(condition="StartsWith", field=TrackField.ALBUM)
57+
comparer = Comparer(condition="StartsWith", field=TrackField.ALBUM, reference_required=True)
5858
assert comparer._expected is None
5959
assert not comparer._converted
6060

0 commit comments

Comments
 (0)