Uploaded image for project: 'Picard'
  1. Picard
  2. PICARD-1076

Division by zero in track.py

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Normal Normal
    • None
    • 1.3.2
    • Tags & Metadata
    • None
    • Ubuntu 16.10

       
       
      When attempting to load the album with the url http://127.0.0.1:8000/openalbum?id=eaa76f67-cb64-48a8-81e6-d744020c4f6b&t=1493212259 Picard would throw multiple division by error traces like the following in track.py that would result in the loading of the album to never complete.

      E: 17:18:10 Traceback (most recent call last):
      File "/usr/lib/picard/picard/album.py", line 303, in _finalize_loading_track
      run_track_metadata_processors(self, tm, self._release_node, track_node)
      File "/usr/lib/picard/picard/metadata.py", line 315, in run_track_metadata_processors
      _track_metadata_processors.run(tagger, metadata, track, release)
      File "/usr/lib/picard/picard/plugin.py", line 273, in run
      function(*args, **kwargs)
      File "/home/bob/.config/MusicBrainz/Picard/plugins/lastfmng/_init_.py", line 77, in track_metadata_processor
      lfmws = LastFMTagger(album, metadata, release_node)
      File "/home/bob/.config/MusicBrainz/Picard/plugins/lastfmng/plugin.py", line 193, in _init_
      super(LastFmMixin, self)._init_(album, metadata, release_node)
      File "/home/bob/.config/MusicBrainz/Picard/plugins/lastfmng/plugin.py", line 39, in _init_
      self._load_tracks(release_node, album)
      File "/home/bob/.config/MusicBrainz/Picard/plugins/lastfmng/plugin.py", line 64, in _load_tracks
      track._customize_metadata()
      File "/usr/lib/picard/picard/track.py", line 124, in _customize_metadata
      self._convert_folksonomy_tags_to_genre()
      File "/usr/lib/picard/picard/track.py", line 142, in _convert_folksonomy_tags_to_genre
      taglist.append((100 * count / maxcount, name))
      ZeroDivisionError: integer division or modulo by zero

      I corrected the issue with the following patch and everything appears to work ok.

      — track.py.orig 2015-01-06 16:01:43.000000000 -0600
      +++ track.py 2017-04-26 17:26:35.177918640 -0500
      @@ -137,6 +137,8 @@
      return

      1. Convert counts to values from 0 to 100
        maxcount = max(tags.values())
        + if maxcount == 0:
        + maxcount = 1
        taglist = []
        for name, count in tags.items():
        taglist.append((100 * count / maxcount, name))

       

            Unassigned Unassigned
            parkrain Bob Mroczka
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Version Package