diff --git a/src/dso_api/dynamic_api/filters/lookups.py b/src/dso_api/dynamic_api/filters/lookups.py index ecb8af505..2ab2bc24f 100644 --- a/src/dso_api/dynamic_api/filters/lookups.py +++ b/src/dso_api/dynamic_api/filters/lookups.py @@ -51,7 +51,7 @@ def as_sql(self, compiler, connection): # Allow field__not=value to return NULL fields too. if field_type in ["CharField", "TextField"] and not self.lhs.field.primary_key: return ( - f"{lhs} IS NULL OR UPPER({lhs}) != UPPER({rhs})", + f"({lhs} IS NULL OR UPPER({lhs}) != UPPER({rhs}))", list(lhs_params + lhs_params) + [rhs.upper() if isinstance(rhs, str) else rhs for rhs in rhs_params], )