{"record":{"id":"b7ea8ad2efc0cd0a","repo":"mattermost-community/focalboard","slug":"searchboardsforuserinteam-error-getting-channelmem","errorCode":null,"errorMessage":"SearchBoardsForUserInTeam error getting channelMemberBoardsSQL: %w","messagePattern":"SearchBoardsForUserInTeam error getting channelMemberBoardsSQL: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/services/store/mattermostauthlayer/mattermostauthlayer.go","lineNumber":862,"sourceCode":"\t\tconditions := sq.And{}\n\n\t\tfor _, word := range strings.Split(strings.TrimSpace(term), \" \") {\n\t\t\tconditions = append(conditions, sq.Like{\"lower(b.title)\": \"%\" + strings.ToLower(word) + \"%\"})\n\t\t}\n\n\t\topenBoardsQ = openBoardsQ.Where(conditions)\n\t\tmemberBoardsQ = memberBoardsQ.Where(conditions)\n\t\tchannelMemberBoardsQ = channelMemberBoardsQ.Where(conditions)\n\t}\n\n\tmemberBoardsSQL, memberBoardsArgs, err := memberBoardsQ.ToSql()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"SearchBoardsForUserInTeam error getting memberBoardsSQL: %w\", err)\n\t}\n\n\tchannelMemberBoardsSQL, channelMemberBoardsArgs, err := channelMemberBoardsQ.ToSql()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"SearchBoardsForUserInTeam error getting channelMemberBoardsSQL: %w\", err)\n\t}\n\n\tunionQ := openBoardsQ.\n\t\tPrefix(\"(\").\n\t\tSuffix(\") UNION (\"+memberBoardsSQL, memberBoardsArgs...).\n\t\tSuffix(\") UNION (\"+channelMemberBoardsSQL+\")\", channelMemberBoardsArgs...)\n\n\tunionSQL, unionArgs, err := unionQ.ToSql()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"SearchBoardsForUserInTeam error getting unionSQL: %w\", err)\n\t}\n\n\t// if we're using postgres or sqlite, we need to replace the\n\t// question mark placeholder with the numbered dollar one, now\n\t// that the full query is built\n\tif s.dbType == model.PostgresDBType || s.dbType == model.SqliteDBType {\n\t\tvar rErr error\n\t\tunionSQL, rErr = sq.Dollar.ReplacePlaceholders(unionSQL)","sourceCodeStart":844,"sourceCodeEnd":880,"githubUrl":"https://github.com/mattermost-community/focalboard/blob/a84bbb65e32edf972856b329417096ac413518e9/server/services/store/mattermostauthlayer/mattermostauthlayer.go#L844-L880","documentation":"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.","triggerScenarios":"channelMemberBoardsQ.ToSql() fails after optional Where(conditions) application, during GetBoardsForUserAndTeam search.","commonSituations":"Invalid builder state from conditional construction; squirrel strictness changes after upgrades; malformed inputs propagating into the builder.","solutions":["Guarantee channelMemberBoardsQ has complete SELECT/FROM before ToSql().","Inspect the conditions applied just above line 862 for malformed values.","Verify squirrel version consistency in go.mod/go.sum.","Unit-test the channel-member search branch."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"boards, err := store.GetBoardsForUserAndTeam(userID, teamID, term)\nif err != nil {\n\tif strings.Contains(err.Error(), \"error getting channelMemberBoardsSQL\") {\n\t\tlogger.Error(\"channel member boards query build failed\", \"err\", err)\n\t\treturn nil, ErrInternalSearch\n\t}\n\treturn nil, err\n}","preventionTips":["Ensure channelMemberBoardsQ is complete before ToSql().","Test with and without channel-membership conditions.","Watch squirrel version changes after upgrades."],"tags":["sql","squirrel","query-builder","store"],"backgroundTag":"sql-build-failed","analyzedSha":"a84bbb65e32edf972856b329417096ac413518e9","analyzedAt":"2026-08-30T09:22:20.720Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}