Skip to main content
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes and Ezra Parker and Dan Wilson and John Mason and Jason Dean and Luis Majano and Mark Mandel and Brian Kotek and Wil Genovese and Rob Brooks-Bilson and Andy Matthews and Simeon Bateman and Ray Camden and Chris Rockett and Joe Bernard and Dan Skaggs and Byron Raines and Barney Boisvert and Simon Free and Steve 'Cutter' Blades and Seth Bienek and Katie Bienek and Jeff Coughlin
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes Ezra Parker Dan Wilson John Mason Jason Dean Luis Majano Mark Mandel Brian Kotek Wil Genovese Rob Brooks-Bilson Andy Matthews Simeon Bateman Ray Camden Chris Rockett Joe Bernard Dan Skaggs Byron Raines Barney Boisvert Simon Free Steve 'Cutter' Blades Seth Bienek Katie Bienek Jeff Coughlin

Sequelize - Validation Error: Validation Not Failed

By
Published in

The other day, I was running some Node.js integration tests when I suddenly started seeing the most confusing Sequelize error: "Validation error: Validation not failed". If you have no idea what is causing this error, the message appears to be contradictory on its face - the validation is failing because the validation did not fail. I was befuddled:

To debug this, I started going through the git-log to see what had changed. I discovered that one of my teammates had added a "validate" property to one of the Sequelize Model Schemas:

sequelize.define(
	"Thing",
	{
		name: {
			type: DataTypes.STRING,
			allowNull: false,
			validate: {
				not: [ /\\|\/|:|\?|\*|<|>|"|\||[\x00-\x1F\x7F-\x9F]/g ]
			}
		},
		// ...
	},
	{
		tableName: 'thing'
	}
)

Ahhhh! Notice that there's a validation rule named "not". As in, "Validation NOT failed." So, the error was legitimate; my POST contained data that was matching the Regular Expression defined in the "not" rule. It's just very confusing verbiage (especially when I didn't realize that the Schema had validation rules attached to it).

When I ran across this Sequelize error, I went to Google and Google was no help. So, this post is mostly here to help anyone else who runs into this confusing error and tries to search for some answers.

Want to use code from this post? Check out the license.

Reader Comments

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel
Managed hosting services provided by:
xByte Cloud Logo