Skip to content

Commit

Permalink
#148: Make suggested changes to distinct attribute mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Nov 17, 2020
1 parent 88908f4 commit 84164c9
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions common/icat/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,12 @@ def map_distinct_attributes_to_entity_names(self, distinct_fields, included_fiel
if len(split_fields) == 1:
# Conventional list assignment causes IndexError because -2 is out of
# range of a list with a single element
split_fields.insert(-2, "base")
split_fields.insert(0, "base")

# If a key doesn't exist in the dictionary, create it and assign an empty
# list to it
try:
distinct_field_dict[split_fields[-2]]
except KeyError:
distinct_field_dict[split_fields[-2]] = []

distinct_field_dict[split_fields[-2]].append(split_fields[-1])
distinct_field_dict.setdefault(split_fields[0], [])
distinct_field_dict[split_fields[0]].append(split_fields[-1])

# Remove "base" key as this isn't a valid entity name in Python ICAT
distinct_entities = list(distinct_field_dict.keys())
Expand Down

0 comments on commit 84164c9

Please sign in to comment.