mattermost-community/focalboard · error
SearchBoardsForUser error getting channelMembersSQL: %w
Error message
SearchBoardsForUser error getting channelMembersSQL: %w
What it means
Same class as error 82 but for channelMembersQ: the channel-members SelectBuilder in SearchBoardsForUser could not be converted to SQL by squirrel's ToSql(). The query was structurally invalid at conversion time.
Source
Thrown at server/services/store/mattermostauthlayer/mattermostauthlayer.go:749
conditions := sq.And{}
for _, word := range strings.Split(strings.TrimSpace(term), " ") {
conditions = append(conditions, sq.Like{"lower(b.title)": "%" + strings.ToLower(word) + "%"})
}
boardMembersQ = boardMembersQ.Where(conditions)
teamMembersQ = teamMembersQ.Where(conditions)
channelMembersQ = channelMembersQ.Where(conditions)
}
}
teamMembersSQL, teamMembersArgs, err := teamMembersQ.ToSql()
if err != nil {
return nil, fmt.Errorf("SearchBoardsForUser error getting teamMembersSQL: %w", err)
}
channelMembersSQL, channelMembersArgs, err := channelMembersQ.ToSql()
if err != nil {
return nil, fmt.Errorf("SearchBoardsForUser error getting channelMembersSQL: %w", err)
}
unionQ := boardMembersQ
user, err := s.GetUserByID(userID)
if err != nil {
return nil, err
}
// NOTE: theoretically, could do e.g. `isGuest := !includePublicBoards`
// but that introduces some tight coupling + fragility
if !user.IsGuest {
unionQ = unionQ.
Prefix("(").
Suffix(") UNION ("+channelMembersSQL+")", channelMembersArgs...)
if includePublicBoards {
unionQ = unionQ.Suffix(" UNION ("+teamMembersSQL+")", teamMembersArgs...)
}
} else if includePublicBoards {
unionQ = unionQ.View on GitHub (pinned to a84bbb65e3)
Solutions
- Review the channelMembersQ construction (lines above 749) and guarantee SELECT/FROM clauses are always set.
- Log the built conditions when the error occurs to identify the malformed branch.
- Pin the squirrel version and check for regressions after dependency updates.
- Cover the channel-members path with unit tests including the empty-conditions case.
Defensive patterns
Strategy: try-catch
Try / catch
boards, err := store.SearchBoardsForUser(userID, term)
if err != nil {
if strings.Contains(err.Error(), "error getting channelMembersSQL") {
logger.Error("channel members query build failed", "err", err)
return nil, ErrInternalSearch
}
return nil, err
} Prevention
- Ensure channelMembersQ is fully built on every code path before ToSql().
- Test the search path with empty conditions and with channel filters.
- Keep squirrel dependency versions consistent across modules.
When it happens
Trigger: channelMembersQ.ToSql() fails after the conditional Where(conditions) block — invalid placeholder combination or builder missing required clauses.
Common situations: A code path where channelMembersQ is built only under certain membership conditions and reaches ToSql() unpopulated; squirrel upgrade changing ToSql() strictness; malformed search parameters.
Related errors
- SearchBoardsForUser error getting teamMembersSQL: %w
- SearchBoardsForUserInTeam error getting memberBoardsSQL: %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/6356048c2b4a764a.
Report an issue: GitHub.