Skip to content

Commit

Permalink
Fix type error with newly created remote tags
Browse files Browse the repository at this point in the history
And add some assertions to fail faster when there is type skew.

This hopefully addresses the following exception:

  Traceback (most recent call last):
    ...
    File ".../beets-ibroadcast/beetsplug/ibroadcast/command.py", line 77, in func
      self.upload(item, force=opts.force)
    File ".../beets-ibroadcast/beetsplug/ibroadcast/command.py", line 169, in upload
      self._sync_tags(trackid, item)
    File ".../beets-ibroadcast/beetsplug/ibroadcast/command.py", line 231, in _sync_tags
      self._update_tags(item, lastsync_tagids)
    File ".../beets-ibroadcast/beetsplug/ibroadcast/command.py", line 271, in _update_tags
      item.ib_tagids = '|'.join(tagids)
  TypeError: sequence item 0: expected str instance, int found
  • Loading branch information
ctrueden committed Sep 8, 2021
1 parent 3540d8b commit 02ffdf8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion beetsplug/ibroadcast/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ def _stack_trace(self, e):
if self._verbose():
self.plugin._log.exception(e)

@staticmethod
def _assert_type(obj, expected_type):
assert type(obj) == expected_type

@staticmethod
def _assert_element_type(items, expected_type):
for item in items:
assert type(item) == expected_type

@staticmethod
def _trackid(item):
return int(item.ib_trackid) if hasattr(item, 'ib_trackid') else None
Expand Down Expand Up @@ -193,6 +202,10 @@ def _sync_tags(self, trackid, item):
remote_tagids = set(self._remote_tagids(trackid))
lastsync_tagids = set(self._lastsync_tagids(item))

self._assert_element_type(local_tagids, str)
self._assert_element_type(remote_tagids, str)
self._assert_element_type(lastsync_tagids, str)

locally_added = local_tagids - lastsync_tagids
locally_removed = lastsync_tagids - local_tagids
remotely_added = remote_tagids - lastsync_tagids
Expand Down Expand Up @@ -241,7 +254,7 @@ def _tagid(self, tagname):
# New remote tag -- create it.
self.plugin._log.debug(f"--> Creating remote tag '{tagname}'")
try:
tagid = self.ib.createtag(tagname)
tagid = str(self.ib.createtag(tagname))
self.ib.tags[tagid] = {'name': tagname}
self.tags[tagname] = {'id': tagid}
return tagid
Expand Down

0 comments on commit 02ffdf8

Please sign in to comment.