{"record":{"id":"5a35d6deb62019c9","repo":"instructure/canvas-lms","slug":"search-term-must-be-at-least-searchtermhelper-min-search","errorCode":null,"errorMessage":"search term must be at least #{SearchTermHelper::MIN_SEARCH_TERM_LENGTH} characters","messagePattern":"search term must be at least #(.+?) characters","errorType":"validation","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"warning","filePath":"app/graphql/types/account_users_filter_input_type.rb","lineNumber":56,"sourceCode":"           required: false\n\n  argument :include_deleted_users,\n           Boolean,\n           \"Include users with deleted pseudonyms\",\n           required: false\n\n  argument :temporary_enrollment_recipients,\n           Boolean,\n           \"Only include temporary enrollment recipients\",\n           required: false\n\n  argument :temporary_enrollment_providers,\n           Boolean,\n           \"Only include temporary enrollment providers\",\n           required: false\n\n  def prepare_search_term(term)\n    if term.present? && term.length < SearchTermHelper::MIN_SEARCH_TERM_LENGTH\n      raise GraphQL::ExecutionError,\n            \"search term must be at least #{SearchTermHelper::MIN_SEARCH_TERM_LENGTH} characters\"\n    end\n    term\n  end\nend\n","sourceCodeStart":38,"sourceCodeEnd":63,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/types/account_users_filter_input_type.rb#L38-L63","documentation":"GraphQL input-object prepare hook validation in AccountUsersFilterInputType. prepare_search_term runs when the search argument is coerced; if the caller passes a term shorter than SearchTermHelper::MIN_SEARCH_TERM_LENGTH, a GraphQL::ExecutionError is raised so the query fails with a clear message instead of running a useless/expensive wildcard search.","triggerScenarios":"Querying account.users with a filter whose search term is present but shorter than MIN_SEARCH_TERM_LENGTH (e.g. search: \"ab\" when the minimum is 3).","commonSituations":"UI autocomplete sending partial keystrokes to the GraphQL API; clients not knowing the server-side minimum length; tests hardcoding short search strings.","solutions":["Lengthen the search term to at least SearchTermHelper::MIN_SEARCH_TERM_LENGTH characters before sending","Have the client validate/hold back short terms until the minimum is met (debounce + length check)","Check SearchTermHelper::MIN_SEARCH_TERM_LENGTH and mirror it in client-side validation"],"exampleFix":"// before\nusers(searchFilter: { search: \"ab\" }) { ... }\n// after\nusers(searchFilter: { search: \"abc\" }) { ... }","handlingStrategy":"validation","validationCode":"const MIN_SEARCH_TERM_LENGTH = 3 // mirror SearchTermHelper::MIN_SEARCH_TERM_LENGTH\nif (term && term.length >= MIN_SEARCH_TERM_LENGTH) runQuery({ search: term })","typeGuard":"function hasMinLength(term, min) { return typeof term === 'string' && term.length >= min }","tryCatchPattern":null,"preventionTips":["Mirror SearchTermHelper::MIN_SEARCH_TERM_LENGTH in client constants","Debounce search inputs and require minimum length before firing","Omit the search argument when the term is empty or too short"],"tags":["graphql","input-validation","search"],"backgroundTag":"value-out-of-range","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}