Skip to content

Datatypes validations are too strict! #4314

Closed

Description

@janmeier

Yes, we know - yes we are going to fix it soon :). However, your contributions are also very welcomed

I've closed the issues linked here, since they all relate to the same basic problem.

Important: I don't think we should roll back the validation function - it still has its merits. For affected users, either roll back to 3.4.1, or remove the validte function DataTypes.INTEGER.validate = function () { return true };

As mentioned, at least some validators should only be run on update / insert. My suggestion would be to add a context parameter to the validate function, so for example uuids are only validated when inserted / updated. We might also add a context like nested, to show the the value comes from a $like { $any or similar, and might be an array, object etc.

Activity

  1. added
    type: bug
    regression
    on Aug 13, 2015
  2. Gedzis commented on Aug 18, 2015

    @Gedzis

    For Similarly, numbers are valid strings validation function could be updated to

    STRING.prototype.validate = function(value) {
      var objectType = Object.prototype.toString.call(value);
      if ( objectType !== '[object String]' && objectType !== '[object Number]') {
        if (this.options.binary) {
          if (Buffer.isBuffer(value)) {
            return true;
          }
        }
        throw new sequelizeErrors.ValidationError(util.format('%j is not a valid string', value));
      }
    
      return true;
    };
    
  3. janmeier commented on Aug 18, 2015

    @janmeier
    MemberAuthor

    @Gedzis however, we don't want to allow all strings - only strings that are actually numbers :)

  4. defunctzombie commented on Aug 19, 2015

    @defunctzombie
    Contributor

    One way to check that the string is a valid number is to just coerce it to one. IMO this is a better check than more complex ones which become more expensive as well.

    isNaN(+'123') // false
    isNaN(+'foo') // true
    isNaN(+'123+e7') // false
    

    Note: scientific notation is automatically handled so if the db dialect being used doesn't like that, it needs to handle that separately.

  5. defunctzombie commented on Aug 19, 2015

    @defunctzombie
    Contributor

    (Maybe) A flag that disables the validations completely

    Yes please. If I don't care about client side validation in my app and am happy to let the db handle it, I can avoid poorly defined validation code and having it run every time.

  6. defunctzombie commented on Aug 19, 2015

    @defunctzombie
    Contributor

    Also, adding the the DECIMAL type validation is currently completely broken as it will not support numbers outside of the js number range.

    Can you roll a version that disables these validators by default so a more gradual tested rollout of validation can happen?

  7. mickhansen commented on Aug 19, 2015

    @mickhansen
    Contributor

    I'm leaning towards @defunctzombie's argument here, we might need to rollback the validations untill they are working properly (i too was bitten by the fact that i knew my DB could handle a certain value but the Sequelize codebase claimed otherwise).

  8. defunctzombie commented on Aug 19, 2015

    @defunctzombie
    Contributor

    I have also noticed a change to the id field support. If I specify the id field as just a type, then I get not an integer errors but if I use the longer form specification type: ... , primaryKey: ... then it works. Not as much of an issue as I find the longer form to be more explicit and better but it is some additional breakage to possibly look into. Tangentially related to the validators.

    I will add that the validators did help me catch some poorly defined types for my models (don't know how that affects dependent code in practice since the types were mis-defined to integer but were really strings) so having some way to enable them so I can use them in testing and development certainly could be a win.

  9. Julusian commented on Aug 26, 2015

    @Julusian

    I assume this is causing the following error when doing a DATE_SUB inside sequelize.literal

    Unhandled rejection SequelizeValidationError: {"updatedAt":{"gte":{"val":"DATE_SUB(UTC_TIMESTAMP(), INTERVAL 10 SECOND)"}}} is not a valid date
    
  10. janmeier commented on Aug 27, 2015

    @janmeier
    MemberAuthor
  11. beeant commented on Aug 30, 2015

    @beeant

    I'm having the same issue... Error: { [SequelizeValidationError: 60 is not a valid string]

  12. mainakae commented on Sep 3, 2015

    @mainakae

    one more affected :)

    (great work with this library, btw, incredibly usefull and great performing)

    In my humble opinion; validations would be better off by default, and let the user decide if he/she wants an early validation or a DB error. And regarding the case at hand; validations should be performed after type casting (and type casting is paramount here, as missmatches will occur between the diferent data type catalogs of DBMS and js types).

  13. SBero commented on Sep 9, 2015

    @SBero

    Anybody know what's the newest version not affected by the validation issues?

  14. janmeier commented on Sep 9, 2015

    @janmeier
    MemberAuthor

    @SBero , as mentioned in the top post, 3.4.1 ;)

  15. SBero commented on Sep 9, 2015

    @SBero

    Ah missed that. Thanks!

  16. wilsoncook commented on Sep 14, 2015

    @wilsoncook

    Very eager for this being resolved, i'm stucked by upgrading from v2.0.x to v3.7

  17. defunctzombie commented on Sep 14, 2015

    @defunctzombie
    Contributor

    I think the current biggest issue with this is the broken Numeric (or large
    number) support from what my early attempts to upgrade revealed. Any word
    on turning this off or providing an option?

    On Monday, September 14, 2015, Wilson Zeng [email protected] wrote:

    Very eager for this being resolved, i'm stucked by upgrading from v2.0.x
    to v3.7

    —
    Reply to this email directly or view it on GitHub
    #4314 (comment)
    .

  18. mickhansen commented on Sep 14, 2015

    @mickhansen
    Contributor

    I'm still voting for a rollback untill we can implement a flag for this or better fixes.
    It's mostly @janmeier's work so i'll defer to him.

  19. Julusian commented on Sep 14, 2015

    @Julusian

    I agree, something needs to be done. An option to disable all validation would be ideal.
    I really don't like that I've had to limit all my projects to 3.4 in package.json

  20. janmeier commented on Sep 14, 2015

    @janmeier
    MemberAuthor

    I agree, an option it is then - I still believe this is a good feature, but if the consensus against it is strong I would not be completely against removing it? However, I think that with a few adjustments we could make it nice :)

    A lot of people voicing their opinion - so there should be someone here to take on the work and provide a PR as well :)

  21. Julusian commented on Sep 14, 2015

    @Julusian

    I think it is a good feature and shouldnt be removed, but some work is needed to make it less strict, along with a disable option/flag

  22. janmeier commented on Sep 14, 2015

    @janmeier
    MemberAuthor

    @Julusian +1 :)

  23. defunctzombie commented on Sep 14, 2015

    @defunctzombie
    Contributor

    The biggest issue I have with the feature is the broken numeric data type support especially around large numbers. My vote is disabled by default (while it is hashed out) and allow folks to enable it for their test suites (which is a great place to catch some of these things).

    I don't feel as strongly that this feature is a huge win mostly because some databases are more flexible in their data type acceptance than others leading to corner cases catching users off guard (like the Numeric case).

  24. benkaiser commented on Sep 14, 2015

    @benkaiser

    Yeah agree with @defunctzombie and @Julusian . Disable (default or not doesn't bother me), but this would at least allow us to insert the values we need until this is properly implemented.

  25. wilsoncook commented on Sep 15, 2015

    @wilsoncook

    also noticed, the DECIMAL use _.isNumber() to doing an validation, but it will allow Infinity/NaN, so this sql can be happened:

    INSERT INTO `zx_test` (`id`,`decimal`,`updatedAt`,`createdAt`) VALUES (DEFAULT,NaN,'2015-09-15 09:37:12','2015-09-15 09:37:12');

    then ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'field list' throws.
    Why not Validator.isDecimal?
    (APPEND: Sorry about NaN, i have checked postgres/query-generator.js line 880, any NOT TRUE value will not call validate at all.)

  26. self-assigned this
    on Oct 3, 2015
  27. sterlingwes commented on Oct 8, 2015

    @sterlingwes

    I've noticed this specifically with defined primary keys & migrations (ie. no sync()):

    { [SequelizeValidationError: 1 is not a valid string]
      name: 'SequelizeValidationError',
      message: '1 is not a valid string',
      errors: [] } 'SequelizeValidationError: 1 is not a valid string
    

    Confirmed that this error relates to my id column:

      id: {
        type: SQL.INTEGER,
        primaryKey: true,
        autoIncrement: true
      }
    

    The actual insert was formatted correctly and the column is the right data type in postgres.

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

Metadata

Metadata

Assignees

Labels

regressiontype: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions