From d3a0f0bebbb9f135643fd628e2b56efe6959b876 Mon Sep 17 00:00:00 2001 From: Matthew Richards Date: Thu, 1 Oct 2020 16:33:48 +0000 Subject: [PATCH] #145: Fix bug where GET requests without distinct filter sometimes return a 400 --- common/icat/helpers.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/common/icat/helpers.py b/common/icat/helpers.py index 732344aa..44037b77 100644 --- a/common/icat/helpers.py +++ b/common/icat/helpers.py @@ -293,9 +293,13 @@ def entity_to_dict(self, entity, includes, distinct_fields=None): " cause an issue further on in the request" ) if isinstance(target, Entity): - distinct_fields_copy = self.prepare_distinct_fields_for_recursion( - key, distinct_fields - ) + if distinct_fields is not None: + distinct_fields_copy = self.prepare_distinct_fields_for_recursion( + key, distinct_fields + ) + else: + distinct_fields_copy = None + d[key] = self.entity_to_dict( target, includes_copy, distinct_fields_copy ) @@ -304,9 +308,13 @@ def entity_to_dict(self, entity, includes, distinct_fields=None): elif isinstance(target, EntityList): d[key] = [] for e in target: - distinct_fields_copy = self.prepare_distinct_fields_for_recursion( - key, distinct_fields - ) + if distinct_fields is not None: + distinct_fields_copy = self.prepare_distinct_fields_for_recursion( + key, distinct_fields + ) + else: + distinct_fields_copy = None + d[key].append( self.entity_to_dict(e, includes_copy, distinct_fields_copy) )