Repository navigation
fix: skip validation for undefined values while updating - #9587
Conversation
sushantdhiman
left a comment
There was a problem hiding this comment.
Why don't we just filter out undefined from values input? Please add a test to verify instance.update also ignores any undefined values
@sushantdhiman since there is I can do even better and move |
|
https://github.com/sequelize/sequelize/pull/9587/files#diff-a140b60b6a99a8c69f4b5d0d1f1f2bfaR2851 |
|
@sushantdhiman yeah that what I thought at start, but there is no need for that because that's exactly what |
|
So safest option is to filter out |
sushantdhiman
left a comment
There was a problem hiding this comment.
Need some work in tests and its good to go
|
|
||
| it('should not check for notNull Violation for undefined values', function() { | ||
| const ownerId = 2; | ||
| let accountRowId; |
There was a problem hiding this comment.
Get rid of accountRowId, if you do account.findOne you will directly get our target instance, as there is sync in before each.
| name: Math.random().toString() | ||
| }).then(account => { | ||
| accountRowId = account.get('id'); | ||
| const accountVal = { |
There was a problem hiding this comment.
values from accountVal can be passed directly to this.Account.update, no need to keep values as constant.
| }); | ||
| }); | ||
|
|
||
| it('should ignore undefined values', function() { |
There was a problem hiding this comment.
Looks like duplicate of test above, Please add a test here https://github.com/sequelize/sequelize/blob/master/test/integration/instance/update.test.js so we can be sure instance method update also ignores undefined values
There was a problem hiding this comment.
It was one for not null props and one for the nullable props (as it might behave different) but I guess the first one is enough
| })); | ||
| }); | ||
|
|
||
| it('should not check for notNull Violation for undefined values', function() { |
There was a problem hiding this comment.
should ignore undefined values without throwing not null validation
So I had to edit the See if it's fine by you. and whether u like to refactor that |
|
@sushantdhiman Can this be merged in v4? |
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Fixes #7056, after #7167 has failed since it affects the
.createmethod (and should have not).As stated in #7056, while assigning
undefinedvalue into a non-nullable prop and calling.updatea validation Error is raised, yet while assigningundefinedto nullable prop is completely ignored and not shown in the update query, due to themapValueFieldNamesfunction which removesundefinedprops as desired.This also aligning the behavior with #9548 .
BWC checks for non-nullable props :