{"id":"b5ced02e79c3c4a2","repo":"drizzle-team/drizzle-orm","slug":"cannot-pass-undefined-values-to-any-set-operator-b5ced0","errorCode":null,"errorMessage":"Cannot pass undefined values to any set operator","messagePattern":"Cannot pass undefined values to any set operator","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/singlestore-core/dialect.ts","lineNumber":453,"sourceCode":"\n\t\tconst finalQuery =\n\t\t\tsql`${withSql}select${distinctSql} ${selection} from ${tableSql}${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: SingleStoreSelectConfig['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":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/singlestore-core/dialect.ts#L435-L471","documentation":"Thrown at the top of SingleStoreDialect.buildSetOperations (dialect.ts:453) when the destructured first element of the setOperators array is undefined/falsy. This indicates the query's setOperators config contains an undefined entry, which Drizzle treats as an invalid set operation rather than silently producing malformed SQL.","triggerScenarios":"Calling union/unionAll/intersect/except with an undefined argument that gets pushed into setOperators; programmatic query assembly that spreads a sparse array (e.g. `[undefined]`) into the chain; internal addSetOperators receiving a filtered/mapped array that yields undefined.","commonSituations":"Conditionally building a union where a branch returns undefined (`...cond ? qb2 : undefined`); refactoring a set-operator pipeline and accidentally leaving a placeholder; passing a subquery variable that was never assigned.","solutions":["Filter out undefined entries before adding set operators: `operators.filter(Boolean)`.","Ensure every union/intersect/except argument is a concrete select builder, not a possibly-undefined expression.","If a set operator is optional, build the operator list conditionally and only call addSetOperators when at least one defined operator exists."],"exampleFix":"// before\nconst extra = cond ? db.select({a: t.a}).from(t) : undefined;\nawait base.union(extra as any);\n// after\nconst extra = cond ? db.select({a: t.a}).from(t) : null;\nconst q = base;\nif (extra) q.union(extra);","handlingStrategy":"validation","validationCode":"function buildOperators(ops) {\n  return ops.filter((o) => o !== undefined && o !== null);\n}\n// only call addSetOperators / union when result is non-empty","typeGuard":"function hasNoUndefinedOperators(ops) { return ops.every((o) => o !== undefined && o !== null); }","tryCatchPattern":null,"preventionTips":["Filter sparse arrays before adding set operators.","Avoid spreading conditionally-undefined values into union/intersect/except.","Prefer explicit if-guards over inline conditional operator arguments."],"tags":["set-operators","union","singlestore","validation"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}