You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Op.notIn: [] produces logically-wrong SQL under Op.or and Op.not #18248
An empty Op.notIn array (NOT IN ()) is logically always true. Sequelize correctly special-cases it at the top level, but the mechanism is "return an empty string," which is a valid identity element only for AND. Combined via Op.or or negated via Op.not, the empty fragment is silently dropped, changing the meaning of the whole clause and returning the wrong rows.
Steps to reproduce
// (age NOT IN ()) is always true, so OR should match every row:awaitUser.findAll({where: {[Op.or]: [{age: {[Op.notIn]: []}},{name: 'zzz-nonexistent'}]}});// observed: WHERE "name" = 'zzz-nonexistent' -> 0 rows// expected: all rows
Same root cause under Op.not: { [Op.not]: { age: { [Op.notIn]: [] } } } produces an empty WHERE => all rows, when NOT(always-true) should return none. (The AND case is correct; Op.in: [] under OR is fine -- it emits IN (NULL), the correct always-false identity for OR.) Reproduced against sqlite.
Root cause
packages/core/src/abstract-dialect/where-sql-builder.ts: the empty Op.notIn handler returns ''; joinWithLogicalOperator unconditionally filters empty fragments (filter(Boolean)), safe for AND but discarding an always-true operand under OR; and wrapWithNot('') returns '', collapsing NOT(always-true) to "all rows."
Suggested fix
Emit a real always-true boolean literal (1 = 1 / dialect TRUE) for empty Op.notIn instead of '', mirroring how empty Op.in emits the always-false IN (NULL). The top-level behavior (#4859 / #4860) is preserved, and OR/NOT composition becomes correct.
Activity