fix: relax constrain check to allow input containing constrained values#2754
Merged
fix: relax constrain check to allow input containing constrained values#2754
Conversation
bajtos
commented
Apr 15, 2019
| } | ||
| } | ||
| return constrainedData; | ||
| return originalData.map(obj => constrainDataObject(obj, constraint)); |
Member
Author
There was a problem hiding this comment.
This is slightly changing the behavior when the input data is trying to modify the constrained properties. Before my change, we would silently replace values provided by the user with values enforced by the constraint. With my change in place, we reject requests trying to modify constrained properties.
AFAICT, the function constrainDataObjects (notice the plural name!) is not used anywhere in loopback-next codebase and I would find it surprising if anybody was using it directly from 3rd party projects. I consider this change as a backwards-compatible bug fix (not a breaking change).
a807538 to
42948aa
Compare
nabdelgadir
approved these changes
Apr 15, 2019
raymondfeng
reviewed
Apr 15, 2019
packages/repository/src/__tests__/unit/repositories/constraint-utils.unit.ts
Outdated
Show resolved
Hide resolved
raymondfeng
reviewed
Apr 15, 2019
b-admike
approved these changes
Apr 15, 2019
raymondfeng
approved these changes
Apr 15, 2019
42948aa to
ec176db
Compare
…trained values
Consider a Product constraint like `{categoryId: 1}` and a request
to update (patch) Product with the following data:
{
name: 'updated',
categoryId: 1
}
Before this change, such request would be incorrectly rejected.
With this change in place, such requests are allowed.
ec176db to
21a5f82
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consider a Product constraint like
{categoryId: 1}and a requestto update (patch) Product with the following data:
Before this change, such request would be incorrectly rejected.
With this change in place, such requests are allowed.
Fixes #1719, resolves #2658
/cc @foobarrrz
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈