{"id":"71a2f0717d7265e2","repo":"drizzle-team/drizzle-orm","slug":"cannot-pass-undefined-values-to-any-set-operator-71a2f0","errorCode":null,"errorMessage":"Cannot pass undefined values to any set operator","messagePattern":"Cannot pass undefined values to any set operator","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/mysql-core/dialect.ts","lineNumber":495,"sourceCode":"\n\t\tconst finalQuery =\n\t\t\tsql`${withSql}select${distinctSql} ${selection} from ${tableSql}${useIndexSql}${forceIndexSql}${ignoreIndexSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;\n\n\t\tif (setOperators.length > 0) {\n\t\t\treturn this.buildSetOperations(finalQuery, setOperators);\n\t\t}\n\n\t\treturn finalQuery;\n\t}\n\n\tbuildSetOperations(\n\t\tleftSelect: SQL,\n\t\tsetOperators: MySqlSelectConfig['setOperators'],\n\t): SQL {\n\t\tconst [setOperator, ...rest] = setOperators;\n\n\t\tif (!setOperator) {\n\t\t\tthrow new Error('Cannot pass undefined values to any set operator');\n\t\t}\n\n\t\tif (rest.length === 0) {\n\t\t\treturn this.buildSetOperationQuery({ leftSelect, setOperator });\n\t\t}\n\n\t\t// Some recursive magic here\n\t\treturn this.buildSetOperations(\n\t\t\tthis.buildSetOperationQuery({ leftSelect, setOperator }),\n\t\t\trest,\n\t\t);\n\t}\n\n\tbuildSetOperationQuery({\n\t\tleftSelect,\n\t\tsetOperator: { type, isAll, rightSelect, limit, orderBy, offset },\n\t}: {\n\t\tleftSelect: SQL;","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/mysql-core/dialect.ts#L477-L513","documentation":"Thrown by MySqlDialect.buildSetOperations (line 495) when destructuring setOperators yields undefined as the first element. This is a defensive internal invariant: a set operator entry was undefined/missing, which should not be reachable through the public API.","triggerScenarios":"The setOperators array on MySqlSelectConfig contains an undefined entry before being built. Not normally reachable via db.select().union() since those validate inputs; would require manually mutating config.setOperators with undefined or an internal bug.","commonSituations":"Internal/advanced misuse where config.setOperators was patched to contain undefined; version mismatch or monkey-patching of Drizzle internals; extremely rare in normal usage.","solutions":["Avoid manually pushing into query config.setOperators - use the .union()/.intersect()/.except() builder methods.","Ensure you're not passing undefined to addSetOperators; filter out undefined entries first.","If using a forked/patched Drizzle, diff against upstream set-operator handling.","Upgrade to the latest Drizzle version in case this is a fixed internal regression."],"exampleFix":"// before (advanced misuse)\n(query as any).config.setOperators.push(undefined);\nquery.getSQL(); // throws\n\n// after - only push valid operator objects\nconst op = { type: 'union', isAll: false, rightSelect: otherQuery };\n(query as any).config.setOperators.push(op);","handlingStrategy":"validation","validationCode":"// Don't push undefined into config.setOperators\nconst ops = candidateSetOperators.filter((o) => o != null) as NonNullable<typeof candidateSetOperators[number]>[];\nif (ops.length === 0) return; // nothing to build\nquery.addSetOperators(ops);","typeGuard":"function isSetOperator(v: unknown): v is MySqlSelectConfig['setOperators'][number] {\n  return v != null && typeof v === 'object' && 'type' in v && 'rightSelect' in v;\n}","tryCatchPattern":null,"preventionTips":["Use the .union()/.intersect()/.except() builder methods, not manual config mutation.","Filter undefined out of any array before passing to addSetOperators.","Avoid monkey-patching Drizzle internals."],"tags":["mysql","set-operators","internal","validation"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}