Skip to content

Commit

Permalink
#141: Add flag to mark ISIS endpoints
Browse files Browse the repository at this point in the history
- This flag is needed to distinguish ISIS endpoints (that use DISTINCT, but don't select multiple fields) from queries that use a distinct filter (DISTINCT and select multiple fields)
  • Loading branch information
MRichards99 committed Apr 13, 2021
1 parent ede08f2 commit 504e94f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datagateway_api/common/icat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ def get_facility_cycles_for_instrument(

query_aggregate = "COUNT:DISTINCT" if count_query else "DISTINCT"
query = ICATQuery(client, "FacilityCycle", aggregate=query_aggregate)
query.isis_endpoint = True

instrument_id_check = PythonICATWhereFilter(
"facility.instruments.id", instrument_id, "eq",
Expand Down Expand Up @@ -633,6 +634,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)
query.isis_endpoint = True

instrument_id_check = PythonICATWhereFilter(
"facility.instruments.id", instrument_id, "eq",
Expand Down
4 changes: 4 additions & 0 deletions datagateway_api/common/icat/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def __init__(
:raises PythonICATError: If a ValueError is raised when creating a Query(), 500
will be returned as a response
"""
# Needed for ISIS endpoints as they use DISTINCT keyword but don't select
# multiple attributes
self.isis_endpoint = False

try:
log.info("Creating ICATQuery for entity: %s", entity_name)
Expand Down Expand Up @@ -93,6 +96,7 @@ def execute_query(self, client, return_json_formattable=False):
self.query.aggregate == "DISTINCT"
and not count_query
and not self.query.manual_count
and not self.isis_endpoint
):
distinct_query = True
log.info("Extracting the distinct fields from query's conditions")
Expand Down

0 comments on commit 504e94f

Please sign in to comment.