Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulkCreate() validation errors when upgrading to from v2 to v3 #3787

Closed
tshaddix opened this issue May 21, 2015 · 4 comments
Closed

bulkCreate() validation errors when upgrading to from v2 to v3 #3787

tshaddix opened this issue May 21, 2015 · 4 comments

Comments

@tshaddix
Copy link

We have a very simple bulkCreate() call which worked fine before upgrading to v3:

// sessionAccounts = [{ accountId, status, classroomSessionId }];

ClassroomSessionAccount
  .bulkCreate(sessionAccounts, {
    transaction: t,
    validate: true
  });

After upgrading, we now get a bunch of validation errors:

...

  '1':
   { record:
      { dataValues:
         { id: null,
           account_id: 702911,
           status: 'active',
           classroom_session_id: 182,
           created_at: Thu May 21 2015 14:11:20 GMT-0700 (PDT),
           updated_at: Thu May 21 2015 14:11:20 GMT-0700 (PDT) },
        _previousDataValues:
         { accountId: undefined,
           status: undefined,
           classroomSessionId: undefined },
        _changed: { accountId: true, status: true, classroomSessionId: true },
        __options: { '$ref': '$[0]["record"]["__options"]' },
        options: { isNewRecord: true },
        hasPrimaryKeys: true,
        __eagerlyLoadedAssociations: [],
        isNewRecord: true },
     errors:
      { name: 'SequelizeValidationError',
        message: 'notNull Violation: accountId cannot be null,\nnotNull Violation: classroomSessionId cannot be null',
        errors:
         [ { message: 'accountId cannot be null',
             type: 'notNull Violation',
             path: 'accountId',
             value: null },
           { message: 'classroomSessionId cannot be null',
             type: 'notNull Violation',
             path: 'classroomSessionId',
             value: null } ] } } }
...

Here is the model definition:

'use strict';

module.exports = function(sequelize, DataTypes) {
  return sequelize.define(
    'ClassroomSessionAccount',
    {
      id: {
        type: DataTypes.INTEGER(10).UNSIGNED,
        allowNull: false,
        primaryKey: true,
        autoIncrement: true
      },
      accountId: {
        type: DataTypes.INTEGER(11).UNSIGNED,
        allowNull: false,
        field: 'account_id'
      },
      status: {
        type: DataTypes.ENUM('active', 'archived'),
        allowNull: false
      },
      classroomSessionId: {
        type: DataTypes.INTEGER(10).UNSIGNED,
        allowNull: false,
        field: 'classroom_session_id'
      }
    },
    {
      tableName: 'ent_classroom_session_accounts',
      timestamps: true,
      underscored: true
    }
  );
};
@tshaddix tshaddix changed the title bulkCreate() issues when upgrading to from v2 to v3 bulkCreate() validation errors when upgrading to from v2 to v3 May 21, 2015
@mickhansen
Copy link
Contributor

Can you post the SQL aswell?

@tshaddix
Copy link
Author

@mickhansen Thanks for responding. Which SQL would this be? This seems to break before any SQL gets involved.

@mickhansen
Copy link
Contributor

@tshaddix from logging: console.log, i just assumed there would be some :)

But it looks like validations might be run after we convert values to fields.

@tshaddix
Copy link
Author

@mickhansen Def! There is a bit for the transaction:

Executing (8df7232e-2e24-4367-a528-ad1118cdc542): START TRANSACTION;
Executing (8df7232e-2e24-4367-a528-ad1118cdc542): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Executing (8df7232e-2e24-4367-a528-ad1118cdc542): SET autocommit = 1;
Executing (8df7232e-2e24-4367-a528-ad1118cdc542): INSERT INTO `ent_classroom_sessions` (`id`,`started_by`,`start_time`,`end_time`,`source_type`,`classroom_id`,`updated_at`,`created_at`) VALUES (DEFAULT,202764,'2015-05-22 17:31:59','2015-05-22 18:16:59','realtime',1,'2015-05-22 17:31:59','2015-05-22 17:31:59');
Executing (8df7232e-2e24-4367-a528-ad1118cdc542): ROLLBACK;

You can see here we insert into ent_classroom_session before running the bulkCreate.

Please let me know if I can provide anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants