Skip to content

Commit

Permalink
Merge pull request #212 from ral-facilities/bugfix/include-distinct-r…
Browse files Browse the repository at this point in the history
…equests-#211

Bugfix/include distinct requests #211
  • Loading branch information
MRichards99 authored Mar 25, 2021
2 parents 04eafd5 + 02778a2 commit 671b33d
Show file tree
Hide file tree
Showing 5 changed files with 572 additions and 303 deletions.
17 changes: 13 additions & 4 deletions datagateway_api/common/icat/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,15 @@ def map_distinct_attributes_to_entity_names(self, distinct_fields, included_fiel
# range of a list with a single element
split_fields.insert(0, "base")

# If a key doesn't exist in the dictionary, create it and assign an empty
# list to it
# Check that only an entity name, and attribute name exist
# Code within loop is used for when `split_fields` =
# ['dataset', 'investigation', 'name'] for example
while len(split_fields) > 2:
# If a key doesn't exist in the dictionary, create it and assign an
# empty list to it
distinct_field_dict.setdefault(split_fields[0], [])
split_fields.pop(0)

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

Expand Down Expand Up @@ -303,10 +310,12 @@ def prepare_distinct_fields(self, entity_name, distinct_fields):
:return: A copy of `distinct_fields`, with the data from the entity name put
into the base portion of the dictionary
"""
# Reset base fields
distinct_fields["base"] = []
log.debug("Entity Name: %s, Distinct Fields: %s", entity_name, distinct_fields)

distinct_fields_copy = distinct_fields.copy()

# Reset base fields
distinct_fields_copy["base"] = []
if entity_name in distinct_fields_copy.keys():
distinct_fields_copy["base"] = distinct_fields_copy[entity_name]

Expand Down
Loading

0 comments on commit 671b33d

Please sign in to comment.