Repository: beetbox/beets

Issue:
discogs: Unhandled exception (HTTP 502: The Discogs API is undergoing maintenance. We'll be back in a moment)
### Problem

I had an unhandled exception (temporary error, I guess) with the discogs plugin . I ``import --quiet .``'d the folder and went away for some hours, so I can't reproduce this error now.

The stacktrace:
```
  File "/beets/beetsplug/discogs.py", line 257, in get_master_year
    year = result.fetch('year')
  File "/usr/lib/python3.7/site-packages/discogs_client/models.py", line 245, in fetch
    self.refresh()
  File "/usr/lib/python3.7/site-packages/discogs_client/models.py", line 211, in refresh
    data = self.client._get(self.data['resource_url'])
  File "/usr/lib/python3.7/site-packages/discogs_client/client.py", line 123, in _get
    return self._request('GET', url)
  File "/usr/lib/python3.7/site-packages/discogs_client/client.py", line 120, in _request
    raise HTTPError(body['message'], status_code)
discogs_client.exceptions.HTTPError: 502: The Discogs API is undergoing maintenance. We'll be back in a moment.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/beet", line 11, in <module>
    load_entry_point('beets', 'console_scripts', 'beet')()
  File "/beets/beets/ui/__init__.py", line 1266, in main
    _raw_main(args)
  File "/beets/beets/ui/__init__.py", line 1253, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/beets/beets/ui/commands.py", line 955, in import_func
    import_files(lib, paths, query)
  File "/beets/beets/ui/commands.py", line 925, in import_files
    session.run()
  File "/beets/beets/importer.py", line 329, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/beets/beets/util/pipeline.py", line 445, in run_parallel
    six.reraise(exc_info[0], exc_info[1], exc_info[2])
  File "/usr/lib/python3.7/site-packages/six.py", line 693, in reraise
    raise value
  File "/beets/beets/util/pipeline.py", line 312, in run
    out = self.coro.send(msg)
  File "/beets/beets/util/pipeline.py", line 194, in coro
    func(*(args + (task,)))
  File "/beets/beets/importer.py", line 1351, in lookup_candidates
    task.lookup_candidates()
  File "/beets/beets/importer.py", line 641, in lookup_candidates
    autotag.tag_album(self.items, search_ids=self.search_ids)
  File "/beets/beets/autotag/match.py", line 460, in tag_album
    va_likely):
  File "/beets/beets/plugins.py", line 571, in decorated
    for v in generator(*args, **kwargs):
  File "/beets/beets/autotag/hooks.py", line 620, in album_candidates
    for candidate in plugins.candidates(items, artist, album, va_likely):
  File "/beets/beets/plugins.py", line 381, in candidates
    for candidate in plugin.candidates(items, artist, album, va_likely):
  File "/beets/beetsplug/discogs.py", line 176, in candidates
    return self.get_albums(query)
  File "/beets/beetsplug/discogs.py", line 245, in get_albums
    return [album for album in map(self.get_album_info, releases[:5])
  File "/beets/beetsplug/discogs.py", line 245, in <listcomp>
    return [album for album in map(self.get_album_info, releases[:5])
  File "/beets/beetsplug/discogs.py", line 335, in get_album_info
    original_year = self.get_master_year(master_id) if master_id else year
  File "/beets/beetsplug/discogs.py", line 262, in get_master_year
    self._log.debug(u'API Error: {0} (query: {1})', e, result._uri)
AttributeError: 'Master' object has no attribute '_uri'
```

### Setup

* OS: Linux
* Python version: 3.7.3
* beets version: 1.4.8, git 81c5ae3f
* Turning off plugins made problem go away (yes/no):  no

I don't think the config is relevant on this case, but the import/discogs parts are:

```yaml
import:                        
    copy: no                   
    move: no                   
    write: no                  
    delete: no                 
    resume: ask                
    incremental: no            
    quiet_fallback: skip       
    none_rec_action: ask       
    timid: no 
    autotag: yes               
    quiet: no                  
    singletons: no             
    default_action: apply
discogs:
    apikey: REDACTED
    apisecret: REDACTED
    tokenfile: discogs_token.json
    source_weight: 0.5
    user_token: REDACTED
```



Discussion:
Thanks! Looks like that, in the two places where we currently use `result._uri` in the error logging call, we need to either remove that lookup or find the new name for that field we want.

Resolving patch:
diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py
--- a/beetsplug/discogs.py
+++ b/beetsplug/discogs.py
@@ -208,7 +208,8 @@ def album_for_id(self, album_id):
             getattr(result, 'title')
         except DiscogsAPIError as e:
             if e.status_code != 404:
-                self._log.debug(u'API Error: {0} (query: {1})', e, result._uri)
+                self._log.debug(u'API Error: {0} (query: {1})', e,
+                                result.data['resource_url'])
                 if e.status_code == 401:
                     self.reset_auth()
                     return self.album_for_id(album_id)
@@ -260,7 +261,8 @@ def get_master_year(self, master_id):
             return year
         except DiscogsAPIError as e:
             if e.status_code != 404:
-                self._log.debug(u'API Error: {0} (query: {1})', e, result._uri)
+                self._log.debug(u'API Error: {0} (query: {1})', e,
+                                result.data['resource_url'])
                 if e.status_code == 401:
                     self.reset_auth()
                     return self.get_master_year(master_id)


Test patch: