To move a Category object from the parent to the new parent, the category should be discarded from the parent and added to the new parent. But when a category is deleted from the parent and added to the new parent, the created_at attribute is overwritten with the newer time than the deleted_at, and as a result, the category exists in both two parents. The converse situation is also true.
Here is a regression test.
def test_previous_change_applied():
subs = SubscriptionList()
category = Category(label='first-order')
subcategory = Category(label='second-order')
to_move = Category(label='to-move')
category.add(subcategory)
subs.add(category)
subs.add(to_move)
assert len(subs) == 2
assert len(subs.categories['first-order']) == 1
subs.discard(to_move)
category.add(to_move)
assert len(subs) == 1
assert len(subs.categories['first-order']) == 2
To work around this, I have to save the SubscriptionList to the stage after deleting the category from the parent, reread the SubscriptionList, and add the category to the new parent.
To move a
Categoryobject from the parent to the new parent, the category should be discarded from the parent and added to the new parent. But when a category is deleted from the parent and added to the new parent, thecreated_atattribute is overwritten with the newer time than thedeleted_at, and as a result, the category exists in both two parents. The converse situation is also true.Here is a regression test.
To work around this, I have to save the
SubscriptionListto the stage after deleting the category from the parent, reread theSubscriptionList, and add the category to the new parent.