From 1e8c72c74cc71099b0088ed7faf80f2edfab4590 Mon Sep 17 00:00:00 2001 From: Jann Stute Date: Mon, 2 Dec 2024 20:31:03 +0100 Subject: [PATCH] fix: AND now works correctly with tags --- .../src/core/library/alchemy/visitors.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tagstudio/src/core/library/alchemy/visitors.py b/tagstudio/src/core/library/alchemy/visitors.py index 1e9ec043..ae6e9d2e 100644 --- a/tagstudio/src/core/library/alchemy/visitors.py +++ b/tagstudio/src/core/library/alchemy/visitors.py @@ -12,7 +12,23 @@ class SQLBoolExpressionBuilder(BaseVisitor): return or_(*[self.visit(element) for element in node.elements]) def visit_and_list(self, node: ANDList) -> ColumnExpressionArgument: - return and_(*[self.visit(term) for term in node.terms]) + return and_( + *[ + Entry.id.in_( + # TODO maybe try to figure out how to remove this code duplication + # My attempts to do this lead to very weird and (to me) unexplainable + # errors. Even just extracting the part up until the where to a seperate + # function leads to an error eventhough that shouldn't be possible. + # -Computerdores + select(Entry.id) + .outerjoin(Entry.tag_box_fields) + .outerjoin(TagBoxField.tags) + .outerjoin(TagAlias) + .where(self.visit(term)) + ) + for term in node.terms + ] + ) def visit_constraint(self, node: Constraint) -> ColumnExpressionArgument: if len(node.properties) != 0: @@ -51,7 +67,7 @@ class SQLBoolExpressionBuilder(BaseVisitor): def visit_not(self, node: Not) -> ColumnExpressionArgument: return ~Entry.id.in_( - # TODO TSQLANG there is technically code duplication from Library.search_library here + # TODO TSQLANG this is technically code duplication, refer to TODO above for why select(Entry.id) .outerjoin(Entry.tag_box_fields) .outerjoin(TagBoxField.tags)