# Buggy code
def update_by_date(self, this_date=date.today()):
    if this_date is None:  # this_date might be None
        return

    date_text = urwid.Text(
        this_date.strftime(self.eventcolumn.pane.conf["locale"]["longdateformat"])
    )
    events = sorted(self.eventcolumn.pane.collection.get_events_on(this_date))

    event_list = [
        urwid.AttrMap(
            U_Event(event, this_date=this_date, eventcolumn=self.eventcolumn),
            "calendar " + event.calendar,
            "reveal focus",
        )
        for event in events
    ]
    event_count = len(event_list)
    if not event_list:
        event_list = [urwid.Text("no scheduled events")]
    self.list_walker = urwid.SimpleFocusListWalker(event_list)
    self._w = urwid.Frame(urwid.ListBox(self.list_walker), header=date_text)
    return event_count


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/bin/ikhal", line 9, in <module>
load_entry_point('khal==0.7.1.dev128+ng619ddd6.d20160219', 'console_scripts', 'ikhal')()
File "/usr/lib/python3.5/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/usr/lib/python3.5/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.5/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/lib/python3.5/site-packages/khal/cli.py", line 361, in interactive_cli
controllers.interactive(build_collection(ctx), ctx.obj['conf'])
File "/usr/lib/python3.5/site-packages/khal/controllers.py", line 209, in interactive
description='do something')
File "/usr/lib/python3.5/site-packages/khal/ui/__init__.py", line 715, in __init__
get_styles=collection.get_styles
File "/usr/lib/python3.5/site-packages/khal/ui/calendarwidget.py", line 591, in __init__
self.set_focus_date(initial)
File "/usr/lib/python3.5/site-packages/khal/ui/calendarwidget.py", line 605, in set_focus_date
self.box.set_focus_date(a_day)
File "/usr/lib/python3.5/site-packages/khal/ui/calendarwidget.py", line 295, in set_focus_date
self.body.set_focus_date(a_day)
File "/usr/lib/python3.5/site-packages/khal/ui/calendarwidget.py", line 370, in set_focus_date
self[self.focus]._set_focus_position(column)
File "/usr/lib/python3.5/site-packages/khal/ui/calendarwidget.py", line 139, in _set_focus_position
self.on_date_change(self.contents[position][0].date)
File "/usr/lib/python3.5/site-packages/khal/ui/__init__.py", line 764, in show_date
self.eventscolumn.original_widget.current_date = date
File "/usr/lib/python3.5/site-packages/khal/ui/__init__.py", line 312, in current_date
if len(self.events.events) > 0:
AttributeError: 'EventList' object has no attribute 'events'

# Fixed code
def update_by_date(self, this_date=date.today()):
    if this_date is None:  # this_date might be None
        return

    date_text = urwid.Text(
        this_date.strftime(self.eventcolumn.pane.conf["locale"]["longdateformat"])
    )
    self.events = sorted(self.eventcolumn.pane.collection.get_events_on(this_date))

    event_list = [
        urwid.AttrMap(
            U_Event(event, this_date=this_date, eventcolumn=self.eventcolumn),
            "calendar " + event.calendar,
            "reveal focus",
        )
        for event in self.events
    ]
    event_count = len(event_list)
    if not event_list:
        event_list = [urwid.Text("no scheduled events")]
    self.list_walker = urwid.SimpleFocusListWalker(event_list)
    self._w = urwid.Frame(urwid.ListBox(self.list_walker), header=date_text)
    return event_count