# Buggy code
def do_i_hate_this(
    cls, task, genre_patterns, artist_patterns, album_patterns, whitelist_patterns
):
    """Process group of patterns (warn or skip) and returns True if
    task is hated and not whitelisted.
    """
    hate = False
    try:
        genre = task.items[0].genre
    except:
        genre = ""
    if genre and genre_patterns:
        if cls.match_patterns(genre, genre_patterns):
            hate = True
    if not hate and task.cur_album and album_patterns:
        if cls.match_patterns(task.cur_album, album_patterns):
            hate = True
    if not hate and task.cur_artist and artist_patterns:
        if cls.match_patterns(task.cur_artist, artist_patterns):
            hate = True
    if hate and whitelist_patterns:
        if cls.match_patterns(task.cur_artist, whitelist_patterns):
            hate = False
    return hate


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/bin/beet", line 8, in <module>
load_entry_point('beets==1.3.0', 'console_scripts', 'beet')()
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beets/ui/__init__.py", line 776, in main
_raw_main(args)
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beets/ui/__init__.py", line 768, in _raw_main
subcommand.func(lib, suboptions, subargs)
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beets/ui/commands.py", line 845, in import_func
import_files(lib, paths, query)
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beets/ui/commands.py", line 783, in import_files
session.run()
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beets/importer.py", line 341, in run
pl.run_parallel(QUEUE_SIZE)
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beets/util/pipeline.py", line 243, in run
out = self.coro.send(msg)
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beets/importer.py", line 952, in item_query
plugins.send('import_task_choice', session=session, task=task)
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beets/plugins.py", line 372, in send
handler(**arguments)
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beetsplug/ihate.py", line 104, in import_task_choice_event
self.config['skip_whitelist'].as_str_seq()):
File "/Library/Python/2.7/site-packages/beets-1.3.0-py2.7.egg/beetsplug/ihate.py", line 79, in do_i_hate_this
if not hate and task.cur_album and album_patterns:
AttributeError: 'ImportTask' object has no attribute 'cur_album'

# Fixed code
def do_i_hate_this(
    cls, task, genre_patterns, artist_patterns, album_patterns, whitelist_patterns
):
    """Process group of patterns (warn or skip) and returns True if
    task is hated and not whitelisted.
    """
    hate = False
    try:
        genre = task.items[0].genre
    except:
        genre = ""
    if genre and genre_patterns:
        if cls.match_patterns(genre, genre_patterns):
            hate = True
    if not hate and getattr(task, "cur_album", None) and album_patterns:
        if cls.match_patterns(task.cur_album, album_patterns):
            hate = True
    if not hate and getattr(task, "cur_artist", None) and artist_patterns:
        if cls.match_patterns(task.cur_artist, artist_patterns):
            hate = True
    if hate and whitelist_patterns:
        if cls.match_patterns(task.cur_artist, whitelist_patterns):
            hate = False
    return hate