Skip to content

Commit

Permalink
#119: Add NULL to an empty list when using the in operator of a wher…
Browse files Browse the repository at this point in the history
…e filter

- This will allow the ICAT backend to return a 200 when something like the following is sent as a where filter - `{"id": {"in": []}}`
  • Loading branch information
MRichards99 committed Feb 19, 2021
1 parent 6377ad5 commit 6662f86
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions datagateway_api/common/icat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def create_filter(self):
# Cannot convert straight to tuple as single element tuples contain a
# trailing comma which Python ICAT/JPQL doesn't accept
self.value = str(self.value).replace("[", "(").replace("]", ")")

# DataGateway Search can send requests with blank lists. Adding NULL to the
# filter prevents the API from returning a 500. An empty list will be
# returned instead, equivalent to the DB backend
if self.value == "()":
self.value = "(NULL)"

where_filter = self.create_condition(self.field, "in", self.value)
else:
raise FilterError(f"Bad operation given to where filter: {self.operation}")
Expand Down

0 comments on commit 6662f86

Please sign in to comment.