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
TypeError with sqlite when violating a unique function based index #10016
Using the dialect sqlite and a function based unique index. When persisting to the database a TypeError is thrown when expecting a SequelizeUniqueConstraintError.
'use strict';constSequelize=require('sequelize');constsequelize=newSequelize({dialect: 'sqlite',storage: ':memory:'});constUser=sequelize.define('User',{username: Sequelize.STRING,email: {type: Sequelize.STRING,unique: true}});User.sync().then(()=>{returnsequelize.query('CREATE UNIQUE INDEX lower_case_username ON users ((lower(username)))');}).then(()=>{returnUser.create({username: 'boby'});}).then(()=>{returnUser.create({username: 'boby'});});
What do you expect to happen?
A SequelizeUniqueConstraintError to be thrown.
What is actually happening?
A TypeError is thrown that can't be caught as a rejection on the promise chain.
TypeError: Cannot read property 'replace' of undefined (../sequelize/lib/dialects/abstract/query.js:133:61)
But in the case of an index function the error returned from sqlite looks like:
[19] [SQLITE_CONSTRAINT_UNIQUE] A UNIQUE constraint failed (UNIQUE constraint failed: index 'lower_case_username')
Should I fix this by modifying the blob above to return something other than undefined for the field name? Or should I modify AbstractQuery.getUniqueConstraintErrorMessage() to handle a falsey field?
Activity
justinkalland commentedon Oct 10, 2018
Issue starts here. As the comment says it expects the error to have a table.column and extract the field name from that:
sequelize/lib/dialects/sqlite/query.js
Lines 386 to 390 in ded9755
But in the case of an index function the error returned from sqlite looks like:
Should I fix this by modifying the blob above to return something other than undefined for the field name? Or should I modify AbstractQuery.getUniqueConstraintErrorMessage() to handle a falsey field?
fix(query): handle undefined field on unique constraint error (#10016) (