[GH-ISSUE #2597] SQL syntax error on MySQL due to CAST in is_archived computation #6708

Closed
opened 2026-04-20 17:17:31 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Anduin2017 on GitHub (Apr 11, 2026).
Original GitHub issue: https://github.com/go-vikunja/vikunja/issues/2597

Pre-submission checklist

  • I have searched for existing open or closed issue reports with the same problem.

Description

Recent logs show repeated SQL errors hitting endpoints such as /api/v1/labels, /api/v1/projects, and /api/v1/tasks with MySQL:

Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int)) AS is_archived, all_projects.background_file_id, all_projects.background_b' at line 5

This appears related to CAST(all_projects.is_archived AS int) in the query for grouping projects (in pkg/models/project.go). MySQL's CAST(... AS int) is not valid SQL; the correct syntax is CAST(... AS signed) or CAST(... AS unsigned). This causes all API calls that expand project subqueries or need project lists to fail with error 500, making key features inaccessible on MySQL.

The relevant code from pkg/models/project.go which uses this problematic cast:

// ...
columnStr := strings.Join([]string{
    "all_projects.id",
    "all_projects.title",
    "all_projects.description",
    "all_projects.identifier",
    "all_projects.hex_color",
    "all_projects.owner_id",
    "CASE WHEN all_projects.parent_project_id IS NULL THEN 0 ELSE all_projects.parent_project_id END AS parent_project_id",
    "MAX(CAST(all_projects.is_archived AS int)) AS is_archived",
    "all_projects.background_file_id",
    "all_projects.background_blur_hash",
    "all_projects.position",
    "all_projects.created",
    "all_projects.updated",
}, ", ")

var archivedFilter string
if !opts.getArchived {
    archivedFilter = "HAVING MAX(CAST(all_projects.is_archived AS int)) = 0 "
}
// ...

Calls to these endpoints then fail, breaking various project-related operations.

Vikunja Version

current main branch or recent releases (see logs, e.g., commit 50d6926b56)

Browser and version

N/A (applies to backend SQL)

Can you reproduce the bug on the Vikunja demo site?

No

Screenshots

Image

Error log excerpts:

  • Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int)) AS is_archived, ...'
Originally created by @Anduin2017 on GitHub (Apr 11, 2026). Original GitHub issue: https://github.com/go-vikunja/vikunja/issues/2597 ### Pre-submission checklist - [x] I have searched for existing open or closed issue reports with the same problem. ### Description Recent logs show repeated SQL errors hitting endpoints such as `/api/v1/labels`, `/api/v1/projects`, and `/api/v1/tasks` with MySQL: ``` Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int)) AS is_archived, all_projects.background_file_id, all_projects.background_b' at line 5 ``` This appears related to `CAST(all_projects.is_archived AS int)` in the query for grouping projects (in `pkg/models/project.go`). MySQL's `CAST(... AS int)` is not valid SQL; the correct syntax is `CAST(... AS signed)` or `CAST(... AS unsigned)`. This causes all API calls that expand project subqueries or need project lists to fail with error 500, making key features inaccessible on MySQL. The relevant code from `pkg/models/project.go` which uses this problematic cast: ```go // ... columnStr := strings.Join([]string{ "all_projects.id", "all_projects.title", "all_projects.description", "all_projects.identifier", "all_projects.hex_color", "all_projects.owner_id", "CASE WHEN all_projects.parent_project_id IS NULL THEN 0 ELSE all_projects.parent_project_id END AS parent_project_id", "MAX(CAST(all_projects.is_archived AS int)) AS is_archived", "all_projects.background_file_id", "all_projects.background_blur_hash", "all_projects.position", "all_projects.created", "all_projects.updated", }, ", ") var archivedFilter string if !opts.getArchived { archivedFilter = "HAVING MAX(CAST(all_projects.is_archived AS int)) = 0 " } // ... ``` Calls to these endpoints then fail, breaking various project-related operations. ### Vikunja Version current main branch or recent releases (see logs, e.g., commit 50d6926b564d7cef9c7552c6487b4874cc398f80) ### Browser and version N/A (applies to backend SQL) ### Can you reproduce the bug on the Vikunja demo site? No ### Screenshots <img width="2560" height="977" alt="Image" src="https://github.com/user-attachments/assets/d52f47cb-5e69-44d5-be71-4b507b34342a" /> Error log excerpts: - `Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int)) AS is_archived, ...'`
Author
Owner

@kolaente commented on GitHub (Apr 11, 2026):

Duplicate of #2589

<!-- gh-comment-id:4229624793 --> @kolaente commented on GitHub (Apr 11, 2026): Duplicate of #2589
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#6708