Hi, Frank. I found a bug and I'm at loss as to how to fix it; I see 
several solutions but they may have other impacts...

The bug: Start with an empty file, create a category, then a 
subcategory, then a task. Edit the parent category and click OK. Edit 
the task. The result:

   File 
"/home/jla/WinHome/dev/fraca7/taskcoach-trunk/taskcoachlib/gui/dialog/editor.py",
 
line 531, in getCategoryWithIndex
     category = children[i]
IndexError: list index out of range

After some digging, I found out that when the category's state is 
saved, patterns.Composite makes a copy of the children. Thus, when the 
edit is undone, the category's children are replaced with copies. But 
the global list of categories keeps the old versions.

As default object comparison is based on id, a category and its copy 
are considered different and bad things happen.

First thought: overload __contains__ in Sorter to compare items 
according to their __id. This fails because the copy generates a new 
__id (and I saw a comment about that so I guess it's intended). Would 
keeping the __id in a copy break something ? Does this fix other 
potential bugs due to the same root ?

Second thought: avoid copying in __getstate__, just keep the original 
instances. I'm pretty sure this will have side effects, though a 
quick test didn't trigger any problem. For instance, if someone edits 
a category from the task viewer and then cancels the task edit, the 
category change would not be undone, I think...

The best fix I thought about is the following: instead of copying 
children in Composite.__getstate__, store their states. This would 
require special handling for item deletion/creation but I think it 
would address all issues.

What do you think ?

Cheers
Jérôme

Reply via email to