khal: Importing event without UID makes khal crash

I exported an event and a todo list item using calcurse to ics format with the following command: calcurse --export > mytest.ics It created the following:

BEGIN:VCALENDAR
PRODID:-//calcurse//NONSGML v4.2.2//EN
VERSION:2.0
BEGIN:VEVENT
DTSTART:20170421T220000
DURATION:P0DT1H0M0S
SUMMARY:test calendar item created in calcurse
END:VEVENT
BEGIN:VTODO
PRIORITY:0
SUMMARY:New todo list item created with calcurse
END:VTODO
END:VCALENDAR

And running khal import -r mytest.ics gives me the following error

Traceback (most recent call last):
  File "/home/doron/.local/bin/khal", line 11, in <module>
    load_entry_point('khal==0.9.6.dev1+g72e6761', 'console_scripts', 'khal')()
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/khal/cli.py", line 443, in import_ics
    env={"calendars": ctx.obj['conf']['calendars']},
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/khal/controllers.py", line 546, in import_ics
    vevents = utils.split_ics(ics, random_uid, conf['locale']['default_timezone'])
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/khal/utils.py", line 616, in split_ics
    events_grouped[item['UID']].append(item)
  File "/home/doron/.virtualenv/khal/lib/python3.6/site-packages/icalendar/caselessdict.py", line 45, in __getitem__
    return super(CaselessDict, self).__getitem__(key.upper())
KeyError: 'UID'

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 15 (11 by maintainers)

Most upvoted comments

I’ve encountered the same problem and used the following bash script to automatically add UID’s to ics files.

#!/bin/bash
set -e
while read line
do
	echo $line
	if [ "$line" = "BEGIN:VEVENT" ]
	then
		echo "UID:$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 36)"
	fi
done