adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

Sequelize validation errors are not properly getting handled.

Open AKNiazi opened this issue 6 years ago • 4 comments

I am using Admin Bro with Express and Sequelize.

"admin-bro": "2.2.5",
"admin-bro-expressjs": "2.0.4",
"admin-bro-sequelizejs": "0.4.0",
"sequelize": "5.21.7",

Admin Bro only handles isRequired validation gracefully for non foreign key attributes of a Model. Other validations return internet server error. Following are the validations which are not handled in my use case.

  1. Unique Column Validation
  2. If an attribute is a foreign key.

validation-error

In the above screenshot, mobile number should be unique, but it does not gracefully handle it and 500 is returned.

AKNiazi avatar Jun 28 '20 07:06 AKNiazi

please write you schema definition for this particular field

wojtek-krysiak avatar Jul 02 '20 15:07 wojtek-krysiak

In model its

mobile: {
  type: DataTypes.STRING,
  allowNull: false,
  unique: true
}

In one migration, i added the column

 queryInterface.addColumn('users', 'mobile',{
      type: Sequelize.STRING,
      allowNull: false,
    })

and in a later migration i added the unique contraint as well.

 queryInterface.addConstraint('users', ['mobile'], {
    type: 'unique',
    name: 'users_mobile_unique_constraint'
  })

AKNiazi avatar Jul 02 '20 16:07 AKNiazi

Not sure if this is related https://github.com/SoftwareBrothers/admin-bro-sequelizejs/issues/17

leibowitz avatar Jul 16 '20 11:07 leibowitz

fixed with @admin-bro/[email protected]

wojtek-krysiak avatar Aug 07 '20 11:08 wojtek-krysiak