Skip to content

Commit 1e8c72c

Browse files
committed
fix: AND now works correctly with tags
1 parent 2d778ce commit 1e8c72c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tagstudio/src/core/library/alchemy/visitors.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@ def visit_or_list(self, node: ORList) -> ColumnExpressionArgument:
1212
return or_(*[self.visit(element) for element in node.elements])
1313

1414
def visit_and_list(self, node: ANDList) -> ColumnExpressionArgument:
15-
return and_(*[self.visit(term) for term in node.terms])
15+
return and_(
16+
*[
17+
Entry.id.in_(
18+
# TODO maybe try to figure out how to remove this code duplication
19+
# My attempts to do this lead to very weird and (to me) unexplainable
20+
# errors. Even just extracting the part up until the where to a seperate
21+
# function leads to an error eventhough that shouldn't be possible.
22+
# -Computerdores
23+
select(Entry.id)
24+
.outerjoin(Entry.tag_box_fields)
25+
.outerjoin(TagBoxField.tags)
26+
.outerjoin(TagAlias)
27+
.where(self.visit(term))
28+
)
29+
for term in node.terms
30+
]
31+
)
1632

1733
def visit_constraint(self, node: Constraint) -> ColumnExpressionArgument:
1834
if len(node.properties) != 0:
@@ -51,7 +67,7 @@ def visit_property(self, node: Property) -> None:
5167

5268
def visit_not(self, node: Not) -> ColumnExpressionArgument:
5369
return ~Entry.id.in_(
54-
# TODO TSQLANG there is technically code duplication from Library.search_library here
70+
# TODO TSQLANG this is technically code duplication, refer to TODO above for why
5571
select(Entry.id)
5672
.outerjoin(Entry.tag_box_fields)
5773
.outerjoin(TagBoxField.tags)

0 commit comments

Comments
 (0)