From c366b608da8c5603e225f09eef9dbc4f6d01aab5 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 28 Aug 2016 18:40:59 +0200 Subject: [PATCH] server/search: fix negating complex searches Entering: miko -miko is a contradiction that shouldn't have been returning any matches, but it has nonetheless. This change fixes the construction of negated expressions that use subqueries. --- server/szurubooru/search/configs/util.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/szurubooru/search/configs/util.py b/server/szurubooru/search/configs/util.py index 40fdd15..28418db 100644 --- a/server/szurubooru/search/configs/util.py +++ b/server/szurubooru/search/configs/util.py @@ -127,8 +127,11 @@ def create_subquery_filter( if subquery_decorator: subquery = subquery_decorator(subquery) subquery = subquery.options(sqlalchemy.orm.lazyload('*')) - subquery = filter_func(subquery, criterion, negated) + subquery = filter_func(subquery, criterion, False) subquery = subquery.subquery('t') - return query.filter(left_id_column.in_(subquery)) + expression = left_id_column.in_(subquery) + if negated: + expression = ~expression + return query.filter(expression) return wrapper