-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
What you are doing?
When running the queryGenerator.changeColumnQuery for the Postgres dialect (I haven't checked if other dialects are affected), changing multiple attributes with the ENUM datatype. If one ENUM is provided, it must not be defined "last" in the parameters object passed in (because we are looping over object keys, which occurs in an unreliable order).
What do you expect to happen?
The ENUM definition should only be included in the final generated query exactly once.
What is actually happening?
The same ENUM definition may be included multiple times in the final generated query.
I am working on a failing test to illustrate this, and haven't yet encountered the issue in my actual projects, but @felixfbecker has also looked over this and agrees that the issue exists.
The actual problem is with this line of code:
3.x: https://github.com/sequelize/sequelize/blob/v3/lib/dialects/postgres/query-generator.js#L246
4.x: https://github.com/sequelize/sequelize/blob/master/lib/dialects/postgres/query-generator.js#L217
Because it mutates the query template, which is reused on subsequent loop iterations, any loop iteration that occurs after an enum column will incorrectly contain a duplicate enum definition.
The solution would be to mutate attrSql rather than query when encountering an enum column during a loop.
Dialect: postgres
Sequelize version: 3.x / 4.x
I'll work on a PR too. :)