server: make negated string filters include null values

This commit is contained in:
William Holt 2023-12-16 23:41:24 +11:00
parent 190d795426
commit 1174cf4861

View file

@ -124,11 +124,11 @@ def apply_str_criterion_to_column(
transformer: Callable[[str], str] = wildcard_transformer, transformer: Callable[[str], str] = wildcard_transformer,
) -> SaQuery: ) -> SaQuery:
if isinstance(criterion, criteria.PlainCriterion): if isinstance(criterion, criteria.PlainCriterion):
expr = column.ilike(transformer(criterion.value)) expr = sa.and_(column != None, column.ilike(transformer(criterion.value)))
elif isinstance(criterion, criteria.ArrayCriterion): elif isinstance(criterion, criteria.ArrayCriterion):
expr = sa.sql.false() expr = sa.sql.false()
for value in criterion.values: for value in criterion.values:
expr = expr | column.ilike(transformer(value)) expr = expr | sa.and_(column != None, column.ilike(transformer(value)))
elif isinstance(criterion, criteria.RangedCriterion): elif isinstance(criterion, criteria.RangedCriterion):
raise errors.SearchError( raise errors.SearchError(
"Ranged criterion is invalid in this context. " "Ranged criterion is invalid in this context. "