mattermost-community/focalboard · error
SearchBoardsForUserInTeam error getting memberBoardsSQL: %w
Error message
SearchBoardsForUserInTeam error getting memberBoardsSQL: %w
What it means
In SearchBoardsForUserInTeam, memberBoardsQ.ToSql() failed — the boards-where-user-is-member query builder could not be rendered to SQL/args. A squirrel query-construction error, not a runtime DB error.
Source
Thrown at server/services/store/mattermostauthlayer/mattermostauthlayer.go:857
// and search for all words.
// This should later be upgraded to industrial-strength
// word tokenizer, that uses much more than space
// to break words.
conditions := sq.And{}
for _, word := range strings.Split(strings.TrimSpace(term), " ") {
conditions = append(conditions, sq.Like{"lower(b.title)": "%" + strings.ToLower(word) + "%"})
}
openBoardsQ = openBoardsQ.Where(conditions)
memberBoardsQ = memberBoardsQ.Where(conditions)
channelMemberBoardsQ = channelMemberBoardsQ.Where(conditions)
}
memberBoardsSQL, memberBoardsArgs, err := memberBoardsQ.ToSql()
if err != nil {
return nil, fmt.Errorf("SearchBoardsForUserInTeam error getting memberBoardsSQL: %w", err)
}
channelMemberBoardsSQL, channelMemberBoardsArgs, err := channelMemberBoardsQ.ToSql()
if err != nil {
return nil, fmt.Errorf("SearchBoardsForUserInTeam error getting channelMemberBoardsSQL: %w", err)
}
unionQ := openBoardsQ.
Prefix("(").
Suffix(") UNION ("+memberBoardsSQL, memberBoardsArgs...).
Suffix(") UNION ("+channelMemberBoardsSQL+")", channelMemberBoardsArgs...)
unionSQL, unionArgs, err := unionQ.ToSql()
if err != nil {
return nil, fmt.Errorf("SearchBoardsForUserInTeam error getting unionSQL: %w", err)
}
// if we're using postgres or sqlite, we need to replace theView on GitHub (pinned to a84bbb65e3)
Solutions
- Ensure memberBoardsQ always has SELECT/FROM clauses before ToSql().
- Log the builder construction path when the error occurs.
- Pin/align the squirrel dependency version.
- Add regression tests for SearchBoardsForUserInTeam with empty and populated search terms.
Defensive patterns
Strategy: try-catch
Try / catch
boards, err := store.GetBoardsForUserAndTeam(userID, teamID, term)
if err != nil {
if strings.Contains(err.Error(), "SearchBoardsForUserInTeam error getting memberBoardsSQL") {
logger.Error("member boards query build failed", "err", err)
return nil, ErrInternalSearch
}
return nil, err
} Prevention
- Guarantee memberBoardsQ SELECT/FROM clauses on all paths.
- Cover the in-team search with unit tests.
- Pin and review the squirrel dependency.
When it happens
Trigger: memberBoardsQ built with optional Where(conditions) reaches ToSql() in an invalid state during a search via GetBoardsForUserAndTeam.
Common situations: Builder left without SELECT clause after conditional branches; malformed search term; dependency (squirrel) version drift after go.mod updates.
Related errors
- SearchBoardsForUser error getting teamMembersSQL: %w
- SearchBoardsForUser error getting channelMembersSQL: %w
- SearchBoardsForUserInTeam error getting channelMemberBoardsS
- SearchBoardsForUser error getting unionSQL: %w
- SearchBoardsForUserInTeam error getting unionSQL: %w
AI-assisted analysis of mattermost-community/focalboard@a84bbb65e3 (2026-08-30).
Data as JSON: /api/errors/0423f2d10c19422a.
Report an issue: GitHub.