Skip to content

Category is duplicated when deleted from the parent and added to the new parent. #64

@teddychoi

Description

@teddychoi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions