Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICARD-1302, PICARD-1303, PICARD-1304: Fix crashes #915

Merged
merged 6 commits into from Aug 1, 2018
Next

Fix exception when a release doesn't have any tracks

When trying to match a cluster with the release at
https://musicbrainz.org/release/c8b5f0e6-96d9-4160-a1d9-ddcf005d4482
picard raised an exception because 'track-count' and 'media' were
not defined in the release object.
  • Loading branch information...
antlarr committed Jul 31, 2018
commit 717be2627cd70997f754477325a2f949546e8565
@@ -150,10 +150,13 @@ def compare_to_release_parts(self, release, weights):
except (ValueError, KeyError):
pass
else:
if "title" in weights:
b = release['media'][0]['track-count']
else:
b = release['track-count']
try:
if "title" in weights:
b = release['media'][0]['track-count']
else:
b = release['track-count']
except KeyError:

This comment has been minimized.

Copy link
@samj1912

samj1912 Jul 31, 2018

Member

Could this also raise an IndexError?

This comment has been minimized.

Copy link
@antlarr

antlarr Aug 1, 2018

Author Contributor

I don't think so. If the release contains a media, it must have a first element, and if it doesn't contain a media then it will already raise a KeyError when evaluating release['media']. I don't think there's such a case as release['media'] being an empty list. Or there is?

b = 0
score = 0.0 if a > b else 0.3 if a < b else 1.0
parts.append((score, weights["totaltracks"]))

@@ -172,7 +175,7 @@ def compare_to_release_parts(self, release, weights):
parts.append((score, weights["releasecountry"]))

total_formats = len(preferred_formats)
if total_formats:
if total_formats and 'media' in release:
score = 0.0
subtotal = 0
for medium in release['media']:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.