[GH-ISSUE #1545] [v1.0.0-rc2] Duplicated SQL condition proposed fix #6439

Closed
opened 2026-04-20 17:02:30 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Mattiam2 on GitHub (Sep 25, 2025).
Original GitHub issue: https://github.com/go-vikunja/vikunja/issues/1545

I've noticed debugging the application in the last Vikunja version (v1.0.0-rc2) that when creating a filter with more than two conditions in && or ||, the generated SQL query duplicates the condition in the middle.

For example, if the filter is: A && B && C

The generated SQL condition in "Where" is: A && B && B && C

Editing the code I managed to fix this issue by rewriting the final filter construction in:
8c4fc4780e/pkg/models/task_search.go (L228-L243)

My proposed fix changes that code block to:

if len(dbFilters) > 0 {
	filterCond = dbFilters[0]
	if len(dbFilters) >= 1 {
		for i := range dbFilters {
			if len(dbFilters) > i+1 {
				switch rawFilters[i+1].join {
				case filterConcatOr:
					filterCond = builder.Or(filterCond, dbFilters[i+1])
				case filterConcatAnd:
					filterCond = builder.And(filterCond, dbFilters[i+1])
				}
			}
		}
	}
}
Originally created by @Mattiam2 on GitHub (Sep 25, 2025). Original GitHub issue: https://github.com/go-vikunja/vikunja/issues/1545 I've noticed debugging the application in the last Vikunja version (v1.0.0-rc2) that when creating a filter with more than two conditions in && or ||, the generated SQL query duplicates the condition in the middle. For example, if the filter is: _A && B && C_ The generated SQL condition in "Where" is: _A && **B && B** && C_ Editing the code I managed to fix this issue by rewriting the final filter construction in: https://github.com/go-vikunja/vikunja/blob/8c4fc4780ed1d10d667bb57f3c32ef472844254e/pkg/models/task_search.go#L228-L243 My proposed fix changes that code block to: ``` if len(dbFilters) > 0 { filterCond = dbFilters[0] if len(dbFilters) >= 1 { for i := range dbFilters { if len(dbFilters) > i+1 { switch rawFilters[i+1].join { case filterConcatOr: filterCond = builder.Or(filterCond, dbFilters[i+1]) case filterConcatAnd: filterCond = builder.And(filterCond, dbFilters[i+1]) } } } } } ```
Author
Owner

@kolaente commented on GitHub (Sep 25, 2025):

Do you want to send a PR?

<!-- gh-comment-id:3332410432 --> @kolaente commented on GitHub (Sep 25, 2025): Do you want to send a PR?
Author
Owner

@Mattiam2 commented on GitHub (Sep 25, 2025):

Created the pull request

<!-- gh-comment-id:3332462239 --> @Mattiam2 commented on GitHub (Sep 25, 2025): Created the pull request
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#6439