Skip to content

Commit 343a85d

Browse files
committed
mbsync: use separate structure for old_data
Assigning an attribute on Items doesn't really work here since we try to store that value to the DB as a flexattr.
1 parent 5e09c5e commit 343a85d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

beetsplug/mbsync.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
log = logging.getLogger('beets')
2525

2626

27-
def _print_and_apply_changes(lib, item, move, pretend, write):
27+
def _print_and_apply_changes(lib, item, old_data, move, pretend, write):
2828
"""Apply changes to an Item and preview them in the console. Return
2929
a boolean indicating whether any changes were made.
3030
"""
3131
changes = {}
3232
for key in library.ITEM_KEYS_META:
33-
if 'key' in item._dirty:
34-
changes[key] = item.old_data[key], getattr(item, key)
33+
if key in item._dirty:
34+
changes[key] = old_data[key], getattr(item, key)
3535
if not changes:
3636
return False
3737

@@ -69,7 +69,7 @@ def mbsync_singletons(lib, query, move, pretend, write):
6969
.format(s.title))
7070
continue
7171

72-
s.old_data = dict(s)
72+
old_data = dict(s)
7373

7474
# Get the MusicBrainz recording info.
7575
track_info = hooks.track_for_mbid(s.mb_trackid)
@@ -80,7 +80,7 @@ def mbsync_singletons(lib, query, move, pretend, write):
8080
# Apply.
8181
with lib.transaction():
8282
autotag.apply_item_metadata(s, track_info)
83-
_print_and_apply_changes(lib, s, move, pretend, write)
83+
_print_and_apply_changes(lib, s, old_data, move, pretend, write)
8484

8585

8686
def mbsync_albums(lib, query, move, pretend, write):
@@ -93,8 +93,7 @@ def mbsync_albums(lib, query, move, pretend, write):
9393
continue
9494

9595
items = list(a.items())
96-
for item in items:
97-
item.old_data = dict(item)
96+
old_data = {item: dict(item) for item in items}
9897

9998
# Get the MusicBrainz album information.
10099
album_info = hooks.album_for_mbid(a.mb_albumid)
@@ -116,8 +115,8 @@ def mbsync_albums(lib, query, move, pretend, write):
116115
autotag.apply_metadata(album_info, mapping)
117116
changed = False
118117
for item in items:
119-
changed = _print_and_apply_changes(lib, item, move, pretend,
120-
write) or changed
118+
changed |= _print_and_apply_changes(lib, item, old_data[item],
119+
move, pretend, write)
121120
if not changed:
122121
# No change to any item.
123122
continue

0 commit comments

Comments
 (0)