{"record":{"id":"0423f2d10c19422a","repo":"mattermost-community/focalboard","slug":"searchboardsforuserinteam-error-getting-memberboar","errorCode":null,"errorMessage":"SearchBoardsForUserInTeam error getting memberBoardsSQL: %w","messagePattern":"SearchBoardsForUserInTeam error getting memberBoardsSQL: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/services/store/mattermostauthlayer/mattermostauthlayer.go","lineNumber":857,"sourceCode":"\t\t// and search for all words.\n\t\t// This should later be upgraded to industrial-strength\n\t\t// word tokenizer, that uses much more than space\n\t\t// to break words.\n\n\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","sourceCodeStart":839,"sourceCodeEnd":875,"githubUrl":"https://github.com/mattermost-community/focalboard/blob/a84bbb65e32edf972856b329417096ac413518e9/server/services/store/mattermostauthlayer/mattermostauthlayer.go#L839-L875","documentation":"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.","triggerScenarios":"memberBoardsQ built with optional Where(conditions) reaches ToSql() in an invalid state during a search via GetBoardsForUserAndTeam.","commonSituations":"Builder left without SELECT clause after conditional branches; malformed search term; dependency (squirrel) version drift after go.mod updates.","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."],"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(), \"SearchBoardsForUserInTeam error getting memberBoardsSQL\") {\n\t\tlogger.Error(\"member boards query build failed\", \"err\", err)\n\t\treturn nil, ErrInternalSearch\n\t}\n\treturn nil, err\n}","preventionTips":["Guarantee memberBoardsQ SELECT/FROM clauses on all paths.","Cover the in-team search with unit tests.","Pin and review the squirrel dependency."],"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"}