-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: relax constrain check to allow input containing constrained values #2754
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
| } | ||
| } | ||
| return constrainedData; | ||
| return originalData.map(obj => constrainDataObject(obj, constraint)); |
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.
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
packages/repository/src/__tests__/unit/repositories/constraint-utils.unit.ts
Outdated
Show resolved
Hide resolved
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.
LGTM 💯 .
EDIT: Nitpick on commit message fix: -> fix(repository):
jannyHou
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.
LGTM
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
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 👈