# Buggy code
def delete_instance(vevent, instance):
    """remove a recurrence instance from a VEVENT's RRDATE list

    :type vevent: icalendar.cal.Event
    :type instance: datetime.datetime
    """

    if "RDATE" in vevent and "RRULE" in vevent:
        # TODO check where this instance is coming from and only call the
        # appropriate function
        _add_exdate(vevent, instance)
        _remove_instance(vevent, instance)
    elif "RRULE" in vevent:
        _add_exdate(vevent, instance)
    elif "RDATE" in vevent:
        _remove_instance(vevent, instance)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/ui/__init__.py", line 1296, in start_pane
loop.run()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 278, in run
self._run()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 376, in _run
self.event_loop.run()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 682, in run
self._loop()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 719, in _loop
self._watch_files[fd]()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/raw_display.py", line 393, in <lambda>
event_loop, callback, self.get_available_raw_input())
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/raw_display.py", line 493, in parse_input
callback(processed, processed_codes)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 403, in _update
self.process_input(keys)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 509, in process_input
something_handled |= bool(self.unhandled_input(k))
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 555, in unhandled_input
return self._unhandled_input(input)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/ui/base.py", line 162, in on_key_press
self.backtrack()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/ui/base.py", line 147, in backtrack
cb(data)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/ui/__init__.py", line 1095, in cleanup
event.delete_instance(rec_id)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/khalendar/event.py", line 602, in delete_instance
delete_instance(self._vevents['PROTO'], instance)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/khalendar/utils.py", line 327, in delete_instance
_add_exdate(vevent, instance)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/khalendar/utils.py", line 292, in _add_exdate
exdates.append(dates_from_exdate(vddlist))
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/khalendar/utils.py", line 282, in dates_from_exdate
return [dts.dt for dts in vevent['EXDATE'].dts]
AttributeError: 'list' object has no attribute 'dts'

# Fixed code
def delete_instance(vevent, instance):
    """remove a recurrence instance from a VEVENT's RRDATE list or add it
    to the EXDATE list

    :type vevent: icalendar.cal.Event
    :type instance: datetime.datetime
    """
    # TODO check where this instance is coming from and only call the
    # appropriate function
    if "RRULE" in vevent:
        exdates = _get_all_properties(vevent, "EXDATE")
        exdates += [instance]
        vevent.pop("EXDATE")
        vevent.add("EXDATE", exdates)
    if "RDATE" in vevent:
        rdates = [
            one for one in _get_all_properties(vevent, "RDATE") if one != instance
        ]
        vevent.pop("RDATE")
        if rdates != []:
            vevent.add("RDATE", rdates)