Skip to content

bug when try to insert integer value in string field. #4255

Closed

Description

@sushantdhiman

My Model.js contains a field with type type: DataTypes.STRING(5).

Under Node 0.12 I can insert a integer value to this field without any issue. But under Node 0.10 it gives me error like this -

error: SequelizeValidationError: 2 is not a valid string at STRING.validate (/var/www/test/test/node_modules/sequelize/lib/data-types.js:92:11) at Object.QueryGenerator.escape (/var/www/test/test/node_modules/sequelize/lib/dialects/mysql/query-generator.js:363:22) at Object.QueryGenerator.whereItemQuery (/var/www/test/test/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2130:20) at /var/www/test/test/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1804:25 at /var/www/test/test/node_modules/lodash/index.js:3073:15 at baseForOwn (/var/www/test/test/node_modules/lodash/index.js:2046:14) at Function.forOwn (/var/www/test/test/node_modules/lodash/index.js:3378:16) at Object.QueryGenerator.whereItemsQuery (/var/www/test/test/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1803:9) at Object.QueryGenerator.getWhereConditions (/var/www/test/test/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2180:19) at Object.QueryGenerator.selectQuery (/var/www/test/test/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1393:28) at QueryInterface.select (/var/www/test/test/node_modules/sequelize/lib/query-interface.js:674:25)

I am using Sequelize 3.3.2.

Activity

  1. sushantdhiman commented on Aug 5, 2015

    @sushantdhiman
    ContributorAuthor

    Additional details

    Database : mysql

    sequelize: ^3.3.2
    sequelize-cli: ^1.3.0
    mysql: ~2.5.4

    I have to convert the data to string then it will work with both Node .12 and .10 , It appears to be an issue with validator.

    I am using the bulkCreate to create the records.

  2. promentol commented on Aug 12, 2015

    @promentol

    The same problem with us, need implicitly convert to string

  3. promentol commented on Aug 12, 2015

    @promentol

    But I see if we have integer field and we assign string value, it converts.

  4. sushantdhiman commented on Aug 12, 2015

    @sushantdhiman
    ContributorAuthor

    I am currently using this patch @promentol

    After model setup

    //Fix datatype level validation errors introduced in #3472
    Sequelize.STRING.prototype.validate = function() { return true; };
    Sequelize.INTEGER.prototype.validate = function() { return true; };
    Sequelize.DECIMAL.prototype.validate = function() { return true; };
    Sequelize.TEXT.prototype.validate = function() { return true; };
    Sequelize.BOOLEAN.prototype.validate = function() { return true; };

    I don't know why there is no option to turn this off using some configuration. This update it breaking all Insert / Update queries.

  5. added
    type: bug
    regression
    on Aug 12, 2015
  6. janmeier commented on Aug 12, 2015

    @janmeier
    Member

    @sushantdhiman Because noone thought of implemening that, and noone commented on the PR that it would be a good idea :)

    A PR with that feature would be welcomed.
    I'm going to loosen up some of the validations as well (e.g. a '2' should be a valid string), when I get around to it - but I'm tied up with finishing my thesis right now

  7. janmeier commented on Aug 13, 2015

    @janmeier
    Member

    Merged into #4314

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    regressiontype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions