mattermost-community/focalboard · error

SearchBoardsForUserInTeam error getting channelMemberBoardsS

Error message

SearchBoardsForUserInTeam error getting channelMemberBoardsSQL: %w

What it means

channelMemberBoardsQ.ToSql() failed in SearchBoardsForUserInTeam: the channel-membership boards builder could not be rendered. Analogous to error 86 but for the channel-member branch of the UNION.

Source

Thrown at server/services/store/mattermostauthlayer/mattermostauthlayer.go:862

		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 the
	// question mark placeholder with the numbered dollar one, now
	// that the full query is built
	if s.dbType == model.PostgresDBType || s.dbType == model.SqliteDBType {
		var rErr error
		unionSQL, rErr = sq.Dollar.ReplacePlaceholders(unionSQL)

View on GitHub (pinned to a84bbb65e3)

Solutions

  1. Guarantee channelMemberBoardsQ has complete SELECT/FROM before ToSql().
  2. Inspect the conditions applied just above line 862 for malformed values.
  3. Verify squirrel version consistency in go.mod/go.sum.
  4. Unit-test the channel-member search branch.
Defensive patterns

Strategy: try-catch

Try / catch

boards, err := store.GetBoardsForUserAndTeam(userID, teamID, term)
if err != nil {
	if strings.Contains(err.Error(), "error getting channelMemberBoardsSQL") {
		logger.Error("channel member boards query build failed", "err", err)
		return nil, ErrInternalSearch
	}
	return nil, err
}

Prevention

When it happens

Trigger: channelMemberBoardsQ.ToSql() fails after optional Where(conditions) application, during GetBoardsForUserAndTeam search.

Common situations: Invalid builder state from conditional construction; squirrel strictness changes after upgrades; malformed inputs propagating into the builder.

Related errors


AI-assisted analysis of mattermost-community/focalboard@a84bbb65e3 (2026-08-30). Data as JSON: /api/errors/b7ea8ad2efc0cd0a. Report an issue: GitHub.