• Jérome Perrin's avatar
    BusinessTemplate: fix simulataneous update of categories and paths · 43adfa98
    Jérome Perrin authored
    This addresses the problem of
    https://nexedijs.erp5.net/#/bug_module/20180719-135FAA8 a KeyError
    raised when some categories in a subtree are modified and some are
    removed and the corresponding base category is also installed as a base
    category.
    
    The problem was that both CategoryTemplateItem, which is in charge of
    updating the base category and PathTemplateItem, which is in charge of
    updating the categories listed as path both use the same
    ObjectTemplateItem.install method, with the same object_to_update dict.
    ObjectTemplateItem.install uninstall all objects that are listed in
    object_to_update and not in self._objects so something like this
    happened when business template from
    test_update_business_template_with_category_having_subcategory_tree_modified
    is updated:
    
      1. PathTemplateItem.install is called for the base category,
    portal_categories/test_category/modified/removed looks removed, so it is
    backed up. Because the the parent paths are not parts of self._objects,
    trash tool will create simple trash folder for
    portal_categories/test_category/modified
    
      2. PathTemplateItem.install is called for the paths,
    portal_categories/test_category/modified is modified, so the previous
    version will be backed up. At this point trash tool looks in the trash
    bin and the path for portal_categories/test_category is already present,
    so trash tool sees that path exists and does not return subobjects, so
    after portal_categories/test_category/modified is modified, the subjects
    such as
    portal_categories/test_category/modified/container_in_which_child_is_added
    are not restored and creating 'added' caused a
    KeyError('container_in_which_child_is_added')
    
    The approach is to make CategoryTemplateItem.install only consider base
    categories - ie. objects where path is portal_categories/* and not the
    subobjects, because they don't belong to CategoryTemplateItem but to
    PathTemplateItem.
    Co-authored-by: Georgios Dagkakis's avatarGeorgios Dagkakis <georgios.dagkakis@nexedi.com>
    43adfa98
BusinessTemplate.py 273 KB