# Buggy code
def get_albums(self, query):
    """Returns a list of AlbumInfo objects for a discogs search query."""
    # Strip non-word characters from query. Things like "!" and "-" can
    # cause a query to return no results, even if they match the artist or
    # album title. Use `re.UNICODE` flag to avoid stripping non-english
    # word characters.
    # FIXME: Encode as ASCII to work around a bug:
    # https://github.com/beetbox/beets/issues/1051
    # When the library is fixed, we should encode as UTF-8.
    query = re.sub(r"(?u)\W+", " ", query).encode("ascii", "replace")
    # Strip medium information from query, Things like "CD1" and "disk 1"
    # can also negate an otherwise positive result.
    query = re.sub(rb"(?i)\b(CD|disc)\s*\d+", b"", query)
    try:
        releases = self.discogs_client.search(query, type="release").page(1)
    except CONNECTION_ERRORS:
        self._log.debug(
            "Communication error while searching for {0!r}", query, exc_info=True
        )
        return []
    return [self.get_album_info(release) for release in releases[:5]]


# Traceback (IndexError)
/data/Music/Unsorted/New Stuff/Para One - 2003 - Paraone - Iris - Le Sept - Flynt - Lyricson (Maxi) [CD - FLAC] (6 items)
Finding tags for album "Paraone - Iris - Le sept - Flynt - Lyricson - Paraone - Iris - Le Sept - Flynt - Lyricson".
Candidates:
1. The Kenny Clarke - Francy Boland Big Band - Paris Jazz Concert: TNP - Oct. 29th, 1969, Part 2 (35.9%) (tracks, artist, album, ...) (CD, 2002, DE, LaserLight Digital)
2. A - Z Consolidated - A - Z Consolidated (33.8%) (tracks, album, artist)
3. Μίκης Θεοδωράκης - Βασίλης Τσιτσάνης - Σταμάτης Κόκοτας - Θεοδωράκης - Τσιτσάνης - Κόκοτας (29.3%) (tracks, missing tracks, album, ...) (12" Vinyl, 1985, GR, Μίνως Μάτσας &amp; Υιός Α.Ε.)
4. Pirkko Mannola - Brita Koivunen - Vieno Kekkonen - Pirkko - Brita - Vieno (20.2%) (missing tracks, tracks, artist, ...) (CD, 1989, FI, Finnlevy)
5. _ - _ (7.7%) (missing tracks, tracks, album, ...)
# selection (default 1), Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort? I
Enter release ID: 690105
Traceback (most recent call last):
File "/home/cesar/.local/bin/beet", line 11, in <module>
sys.exit(main())
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/__init__.py", line 1250, in main
_raw_main(args)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/__init__.py", line 1240, in _raw_main
subcommand.func(lib, suboptions, subargs)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/commands.py", line 967, in import_func
import_files(lib, paths, query)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/commands.py", line 944, in import_files
session.run()
File "/home/cesar/.local/lib/python2.7/site-packages/beets/importer.py", line 320, in run
pl.run_parallel(QUEUE_SIZE)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/util/pipeline.py", line 301, in run
out = self.coro.send(msg)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/util/pipeline.py", line 160, in coro
task = func(*(args + (task,)))
File "/home/cesar/.local/lib/python2.7/site-packages/beets/importer.py", line 1285, in user_query
task.choose_match(session)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/importer.py", line 779, in choose_match
choice = session.choose_match(self)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/commands.py", line 755, in choose_match
task.items, search_ids=search_id.split()
File "/home/cesar/.local/lib/python2.7/site-packages/beets/autotag/match.py", line 407, in tag_album
search_cands.extend(hooks.albums_for_id(search_id))
File "/home/cesar/.local/lib/python2.7/site-packages/beets/autotag/hooks.py", line 541, in albums_for_id
plugin_albums = plugins.album_for_id(album_id)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/plugins.py", line 373, in album_for_id
res = plugin.album_for_id(album_id)
File "/home/cesar/.local/lib/python2.7/site-packages/beetsplug/discogs.py", line 188, in album_for_id
return self.get_album_info(result)
File "/home/cesar/.local/lib/python2.7/site-packages/beetsplug/discogs.py", line 225, in get_album_info
result.data['formats'][0].get('descriptions', [])) or None
IndexError: list index out of range

# Fixed code
def get_albums(self, query):
    """Returns a list of AlbumInfo objects for a discogs search query."""
    # Strip non-word characters from query. Things like "!" and "-" can
    # cause a query to return no results, even if they match the artist or
    # album title. Use `re.UNICODE` flag to avoid stripping non-english
    # word characters.
    # FIXME: Encode as ASCII to work around a bug:
    # https://github.com/beetbox/beets/issues/1051
    # When the library is fixed, we should encode as UTF-8.
    query = re.sub(r"(?u)\W+", " ", query).encode("ascii", "replace")
    # Strip medium information from query, Things like "CD1" and "disk 1"
    # can also negate an otherwise positive result.
    query = re.sub(rb"(?i)\b(CD|disc)\s*\d+", b"", query)
    try:
        releases = self.discogs_client.search(query, type="release").page(1)
    except CONNECTION_ERRORS:
        self._log.debug(
            "Communication error while searching for {0!r}", query, exc_info=True
        )
        return []
    return [album for album in map(self.get_album_info, releases[:5]) if album]