fix: skip validation for undefined values while updating #9587
Conversation
Why don't we just filter out |
@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 |
Need some work in tests and its good to go |
@@ -35,6 +35,53 @@ describe(Support.getTestDialectTeaser('Model'), () => { | |||
})); | |||
}); | |||
|
|||
it('should not check for notNull Violation for undefined values', function() { | |||
const ownerId = 2; | |||
let accountRowId; |
sushantdhiman
Jun 24, 2018
Contributor
Get rid of accountRowId
, if you do account.findOne
you will directly get our target instance, as there is sync
in before each.
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 = { |
sushantdhiman
Jun 24, 2018
Contributor
values from accountVal
can be passed directly to this.Account.update
, no need to keep values as constant.
values from accountVal
can be passed directly to this.Account.update
, no need to keep values as constant.
}); | ||
}); | ||
|
||
it('should ignore undefined values', function() { |
sushantdhiman
Jun 24, 2018
Contributor
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
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
jony89
Jun 24, 2018
Author
Contributor
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 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
@@ -35,6 +35,53 @@ describe(Support.getTestDialectTeaser('Model'), () => { | |||
})); | |||
}); | |||
|
|||
it('should not check for notNull Violation for undefined values', function() { |
sushantdhiman
Jun 24, 2018
Contributor
should ignore undefined values without throwing not null validation
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 |
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 test
ornpm run test-DIALECT
pass with this change (including linting)?Description of change
Fixes #7056, after #7167 has failed since it affects the
.create
method (and should have not).As stated in #7056, while assigning
undefined
value into a non-nullable prop and calling.update
a validation Error is raised, yet while assigningundefined
to nullable prop is completely ignored and not shown in the update query, due to themapValueFieldNames
function which removesundefined
props as desired.This also aligning the behavior with #9548 .
BWC checks for non-nullable props :