You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
instance.validate does not do typeValidation #11266
status: in discussionFor issues and PRs. Community and maintainers are discussing the applicability of the issue.type: featureDEPRECATED: replace with the "feature" issue type
When creating a Sequelize instance with typeValidation turned on, I expect that types are validated when calling the validate method on an instance. I expect output from the above code
to be two SequelizeValidationErrors - one saying '"bar" is not a valid integer' and one saying '"baz" is not a valid integer'.
What is actually happening?
Only one error way thrown - the one saying '"baz" is not a valid integer'.
This is because the InstanceValidator does not do anything with typeValidation, while the QueryGenerator (which isn't being used in the build/validate process) does.
I think the behaviour as it stands is problematic because all the write functions in model.js (save, update, upsert, bulkCreate) start by doing instance.validate if options.validate is true. It should therefore be possible to skip a lot of code if type validation fails, instead of finding out much later that the query is invalid.
I have come across another problem relating to this issue.
If you are doing bulkCreate with an array of data containing multiple entries with type validation errors, the way typeValidation works results in a ValidationError being thrown containing only the details of the first validation error, rather than a BulkRecordError like you get for other types of validation.
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
status: in discussionFor issues and PRs. Community and maintainers are discussing the applicability of the issue.type: featureDEPRECATED: replace with the "feature" issue type
Activity
papb commentedon Aug 1, 2019
Actually, I have just checked the docs, what is says for
options.typeValidationis this:So apparently I think your example behaves like the docs say it should.
However, I agree this might be a valid change...
simonbrent commentedon Aug 2, 2019
I think the behaviour as it stands is problematic because all the write functions in model.js (save, update, upsert, bulkCreate) start by doing instance.validate if options.validate is true. It should therefore be possible to skip a lot of code if type validation fails, instead of finding out much later that the query is invalid.
simonbrent commentedon Nov 3, 2020
I have come across another problem relating to this issue.
If you are doing
bulkCreatewith an array of data containing multiple entries with type validation errors, the waytypeValidationworks results in aValidationErrorbeing thrown containing only the details of the first validation error, rather than aBulkRecordErrorlike you get for other types of validation.github-actions commentedon Nov 8, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
simonbrent commentedon Nov 10, 2021
This is still an issue with version 6.9.0