Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescope upload tree when there is only 1 tree in the upload plan #5385

Open
wants to merge 1 commit into
base: production
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions specifyweb/workbench/upload/treerecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ def get_targeted_treedefids(ranks_columns: List[TreeRankCell]) -> Set[int]:

# Handle cases where there are multiple or no treedefs
def handle_multiple_or_no_treedefs(
targeted_treedefids: Set[int], ranks_columns: List[TreeRankCell]
unique_treedef_ids: Set[int], targeted_treedefids: Set[int], ranks_columns: List[TreeRankCell]
) -> Optional[Tuple["ScopedTreeRecord", Optional["WorkBenchParseFailure"]]]:
if not targeted_treedefids:
return self, None
elif len(targeted_treedefids) > 1:
elif len(targeted_treedefids) > 1 and len(unique_treedef_ids) > 1:
logger.warning(f"Multiple treedefs found in row: {targeted_treedefids}")
error_col_name = ranks_columns[0].column_fullname
return self, WorkBenchParseFailure('multipleRanksInRow', {}, error_col_name)
Expand All @@ -368,7 +368,7 @@ def handle_multiple_or_no_treedefs(

# Check if any treedef_id has more than one rank
multiple_ranks = any(len(columns) > 1 for columns in grouped_by_treedef_id.values())
if multiple_ranks:
if multiple_ranks and len(unique_treedef_ids) > 1:
treedef_id = next(
treedef_id
for treedef_id, columns in grouped_by_treedef_id.items()
Expand Down Expand Up @@ -413,13 +413,11 @@ def check_root(root):
tree_def_model, tree_rank_model, tree_node_model = get_models(self.name)

unique_treedef_ids = {tr.treedef_id for tr in self.ranks.keys()}
if len(unique_treedef_ids) == 1:
return self, None

ranks_columns_in_row_not_null = get_not_null_ranks_columns(row)
targeted_treedefids = get_targeted_treedefids(ranks_columns_in_row_not_null)

result = handle_multiple_or_no_treedefs(targeted_treedefids, ranks_columns_in_row_not_null)
result = handle_multiple_or_no_treedefs(unique_treedef_ids, targeted_treedefids, ranks_columns_in_row_not_null)
if result:
return result

Expand All @@ -428,7 +426,7 @@ def check_root(root):
if not targeted_treedefids:
# return self, WorkBenchParseFailure('noRanksInRow', {}, None)
return self, None
elif len(targeted_treedefids) > 1:
elif len(targeted_treedefids) > 1 and len(unique_treedef_ids) > 1:
logger.warning(f"Multiple treedefs found in row: {targeted_treedefids}")
error_col_name = list(ranks_columns_in_row_not_null)[0].column_fullname
return self, WorkBenchParseFailure("multipleRanksInRow", {}, error_col_name)
Expand Down
Loading