-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Description
Today an object can be edited like this:
my_event = calendar.search(...)[0]
my_event.icalendar_component['summary'] = "This is the edited summary"
my_event.save()
This was my invention, so of course I like it - but there are troubles here. First of all, the side effect. Consider those code-lines:
my_event.data
my_event.icalendar_instance
my_event.vobject_instance
my_event.data
It looks like a noop, but this little sequence of commands will efficiently convert the data from a string to an icalendar_instance then to a vobject_instance (via a string), and finally back to a string again. This may cause some problems:
- While the semantics of the object shouldn't be changed by the conversions, the actual data representation may change.
- Ii've grown up in an age where it was important to optimize things not to use too many CPU-cycles and memory. The conversions above makes me cringe a bit - I would guess quite much CPU is spent on wasteful work here.
- In quite some of the internal methods I was earlier always using
my_event.datato avoid conversions - but at some point I gave up, after all we do have an icalendar library for doing icalendar operations for us. Meaning that just internally an object may be tossed from one format to another during ordinary usage of the library. - The data conversion may also cause a data loss in some corner situations. The code below will NOT edit the summary:
my_event = calendar.search(...)[0]
icalendar_component = my_event.icalendar_component['summary']
my_event.data ## now icalendar_component is no longer connected to my_event!
icalendar_component['summary'] = "This is the edited summary"
my_event.save()
Should the API be changed now that before we're releasing 3.0?
I do remember @niccokunzmann reaching out to me earlier on this topic having some thoughts about it, but I can't find back to the conversation.
Metadata
Metadata
Assignees
Labels
No labels