Skip to content

Commit

Permalink
Merge pull request #316 from ral-facilities/bugfix/non-numeric-values…
Browse files Browse the repository at this point in the history
…-with-neq-operator-#315

Make ne and neq operators work with non-numeric values
  • Loading branch information
VKTB authored Feb 2, 2022
2 parents b275fdb + f74efc0 commit a13e699
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion datagateway_api/src/datagateway_api/icat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def create_condition(attribute_name, operator, value):
# distinct filter is used in a request
jpql_value = (
f"{value}"
if operator in ("in", "not in", "!=", "between")
if operator in ("in", "not in", "between")
or str(value).startswith("UPPER")
or "o." in str(value)
else f"'{value}'"
Expand Down
4 changes: 2 additions & 2 deletions test/datagateway_api/icat/filters/test_where_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class TestICATWhereFilter:
"operation, value, expected_condition_value",
[
pytest.param("eq", 5, ["%s = '5'"], id="equal"),
pytest.param("ne", 5, ["%s != 5"], id="not equal (ne)"),
pytest.param("neq", 5, ["%s != 5"], id="not equal (neq)"),
pytest.param("ne", 5, ["%s != '5'"], id="not equal (ne)"),
pytest.param("neq", 5, ["%s != '5'"], id="not equal (neq)"),
pytest.param("like", 5, ["%s like '%%5%%'"], id="like"),
pytest.param("ilike", 5, ["UPPER(%s) like UPPER('%%5%%')"], id="ilike"),
pytest.param("nlike", 5, ["%s not like '%%5%%'"], id="not like"),
Expand Down
2 changes: 1 addition & 1 deletion test/search_api/filters/test_search_api_where_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestSearchAPIWhereFilter:
pytest.param(
SearchAPIWhereFilter("title", "My Dataset 1", "ne"),
"Dataset",
"SELECT o FROM Dataset o WHERE o.name != My Dataset 1",
"SELECT o FROM Dataset o WHERE o.name != 'My Dataset 1'",
id="WHERE filter with non-default operator",
),
pytest.param(
Expand Down

0 comments on commit a13e699

Please sign in to comment.