Skip to content

Commit

Permalink
fix: throw on invalid where (#15375)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The `where` option will now throw if it receives an unsupported value
  • Loading branch information
ephys committed Dec 2, 2022
1 parent 03c0375 commit 6c71dbd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dialects/abstract/query-generator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

import NodeUtil from 'node:util';
import { getTextDataTypeForDialect } from '../../sql-string';
import { rejectInvalidOptions, isNullish, canTreatArrayAsAnd, isColString } from '../../utils/check';
import { TICK_CHAR } from '../../utils/dialect';
Expand Down Expand Up @@ -2967,7 +2968,7 @@ Only named replacements (:name) are allowed in literal() because we cannot guara
});
}

return '1=1';
throw new Error(`Unsupported where option value: ${NodeUtil.inspect(smth)}. Please refer to the Sequelize documentation to learn more about which values are accepted as part of the where option.`);
}

// A recursive parser for nested where conditions
Expand Down
16 changes: 16 additions & 0 deletions test/unit/query-generator/get-where-conditions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from 'chai';
import { sequelize } from '../../support';

describe('QueryGenerator#getWhereConditions', () => {
const queryGenerator = sequelize.queryInterface.queryGenerator;

it('throws if called with invalid arguments', () => {
const User = sequelize.define('User');

expect(() => {
// TODO: https://github.com/sequelize/sequelize/pull/14020 - remove expect-error
// @ts-expect-error
queryGenerator.getWhereConditions(new Date(), User.getTableName(), User);
}).to.throw('Unsupported where option value');
});
});

0 comments on commit 6c71dbd

Please sign in to comment.