diff --git a/common/icat/helpers.py b/common/icat/helpers.py index 275c8f72..d1f8440a 100644 --- a/common/icat/helpers.py +++ b/common/icat/helpers.py @@ -488,7 +488,7 @@ def get_facility_cycles_for_instrument( query_aggregate = "COUNT:DISTINCT" if count_query else "DISTINCT" query = ICATQuery( - client, "FacilityCycle", aggregate=query_aggregate, isis_endpoint=True + client, "FacilityCycle", aggregate=query_aggregate ) instrument_id_check = PythonICATWhereFilter( @@ -573,7 +573,7 @@ def get_investigations_for_instrument_in_facility_cycle( query_aggregate = "COUNT:DISTINCT" if count_query else "DISTINCT" query = ICATQuery( - client, "Investigation", aggregate=query_aggregate, isis_endpoint=True + client, "Investigation", aggregate=query_aggregate ) instrument_id_check = PythonICATWhereFilter( diff --git a/common/icat/query.py b/common/icat/query.py index bcec87da..99fa2d03 100644 --- a/common/icat/query.py +++ b/common/icat/query.py @@ -21,7 +21,6 @@ def __init__( conditions=None, aggregate=None, includes=None, - isis_endpoint=False, ): """ Create a Query object within Python ICAT @@ -39,12 +38,6 @@ def __init__( :param includes: List of related entity names to add to the query so related entities (and their data) can be returned with the query result :type includes: :class:`str` or iterable of :class:`str` - :param isis_endpoint: Flag to determine if the instance will be used for an ISIS - specific endpoint. These endpoints require the use of the DISTINCT aggregate - which is different to the distinct field filter implemented in this API, so - this flag prevents code related to the filter from executing (because it - doesn't need to be on a DISTINCT aggregate) - :type isis_endpoint: :class:`bool` :return: Query object from Python ICAT :raises PythonICATError: If a ValueError is raised when creating a Query(), 500 will be returned as a response @@ -65,7 +58,6 @@ def __init__( " suggesting an invalid argument" ) - self.isis_endpoint = isis_endpoint def execute_query(self, client, return_json_formattable=False): """ @@ -104,19 +96,19 @@ def execute_query(self, client, return_json_formattable=False): if ( self.query.aggregate == "DISTINCT" and not count_query - and not self.isis_endpoint ): log.info("Extracting the distinct fields from query's conditions") # Check query's conditions for the ones created by the distinct filter distinct_attributes = self.iterate_query_conditions_for_distinctiveness() - mapped_distinct_fields = self.map_distinct_attributes_to_entity_names( - distinct_attributes, flat_query_includes - ) - log.debug( - "Attribute names used in the distinct filter, mapped to the entity they" - " are a part of: %s", - mapped_distinct_fields, - ) + if distinct_attributes != []: + mapped_distinct_fields = self.map_distinct_attributes_to_entity_names( + distinct_attributes, flat_query_includes + ) + log.debug( + "Attribute names used in the distinct filter, mapped to the entity they" + " are a part of: %s", + mapped_distinct_fields, + ) if return_json_formattable: log.info("Query results will be returned in a JSON format") @@ -276,8 +268,7 @@ def map_distinct_attributes_to_entity_names(self, distinct_fields, included_fiel """ # Mapping which entities have distinct fields - distinct_field_dict = {} - distinct_field_dict["base"] = [] + distinct_field_dict = {"base": []} for field in distinct_fields: split_fields = field.split(".")