From 174f84514aff36c99bc975d383857a4ea19c3acd Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Wed, 18 May 2022 10:17:34 +0300 Subject: [PATCH] Fix no destination when merging projects --- apiserver/bll/project/project_bll.py | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/apiserver/bll/project/project_bll.py b/apiserver/bll/project/project_bll.py index 4ac0f24..fcea208 100644 --- a/apiserver/bll/project/project_bll.py +++ b/apiserver/bll/project/project_bll.py @@ -63,20 +63,24 @@ class ProjectBLL: source=source_id ) source = Project.get(company, source_id) - destination = Project.get(company, destination_id) - if source_id in destination.path: - raise errors.bad_request.ProjectCannotBeMergedIntoItsChild( - source=source_id, destination=destination_id - ) + if destination_id: + destination = Project.get(company, destination_id) + if source_id in destination.path: + raise errors.bad_request.ProjectCannotBeMergedIntoItsChild( + source=source_id, destination=destination_id + ) + else: + destination = None children = _get_sub_projects( [source.id], _only=("id", "name", "parent", "path") )[source.id] - cls.validate_projects_depth( - projects=children, - old_parent_depth=len(source.path) + 1, - new_parent_depth=len(destination.path) + 1, - ) + if destination: + cls.validate_projects_depth( + projects=children, + old_parent_depth=len(source.path) + 1, + new_parent_depth=len(destination.path) + 1, + ) moved_entities = 0 for entity_type in (Task, Model): @@ -147,10 +151,8 @@ class ProjectBLL: raise errors.bad_request.ProjectSourceAndDestinationAreTheSame( location=new_parent.name if new_parent else "" ) - if ( - new_parent - and project_id == new_parent.id - or project_id in new_parent.path + if new_parent and ( + project_id == new_parent.id or project_id in new_parent.path ): raise errors.bad_request.ProjectCannotBeMovedUnderItself( project=project_id, parent=new_parent.id