# Buggy code
def get_master_year(self, master_id):
    """Fetches a master release given its Discogs ID and returns its year
    or None if the master release is not found.
    """
    self._log.debug("Searching for master release {0}", master_id)
    result = Master(self.discogs_client, {"id": master_id})

    self.request_start()
    try:
        year = result.fetch("year")
        self.request_finished()
        return year
    except DiscogsAPIError as e:
        if e.status_code != 404:
            self._log.debug("API Error: {0} (query: {1})", e, result._uri)
            if e.status_code == 401:
                self.reset_auth()
                return self.get_master_year(master_id)
        return None
    except CONNECTION_ERRORS:
        self._log.debug("Connection error in master release lookup", exc_info=True)
        return None


# Traceback (discogs_client.exceptions.HTTPError)
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'

# Fixed code
def get_master_year(self, master_id):
    """Fetches a master release given its Discogs ID and returns its year
    or None if the master release is not found.
    """
    self._log.debug("Searching for master release {0}", master_id)
    result = Master(self.discogs_client, {"id": master_id})

    self.request_start()
    try:
        year = result.fetch("year")
        self.request_finished()
        return year
    except DiscogsAPIError as e:
        if e.status_code != 404:
            self._log.debug(
                "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)
        return None
    except CONNECTION_ERRORS:
        self._log.debug("Connection error in master release lookup", exc_info=True)
        return None