-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix: skip validation for undefined values while updating #9587
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
Conversation
sushantdhiman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
|
@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 :