Opened 8 years ago
Closed 8 years ago
#39341 closed defect (bug) (fixed)
`wp.api.utils.decorateFromRoute` should use `_.extend` not `_.union`
Reported by: | Magenta Cuda | Owned by: | adamsilverstein |
---|---|---|---|
Milestone: | 4.7.3 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-patch dev-feedback needs-testing needs-unit-tests reporter-feedback fixed-major |
Focuses: | javascript | Cc: |
Description
modelInstance.prototype.options = _.union( routeEndpoint.args, modelInstance.prototype.options );
Are not the arguments to _.union objects not arrays? In which case _.extend would be more appropriate.
Attachments (2)
Change History (13)
#1
@
8 years ago
- Focuses javascript added
- Owner set to adamsilverstein
- Status changed from new to assigned
#2
@
8 years ago
- Keywords has-patch dev-feedback needs-testing needs-unit-tests added
@Magenta Cuda
I dug into the code a bit and for our default routes the model prototypes didn't have default options or args, so the _.union
call was never reached. You are correct though that args
or options
at this point would be an object, not an array, so _.extend
is more appropriate here.
In 39341.diff I fixed up the logic and switched from union to extend. If you have an issue that was caused by this bug I would appreciate if you could test the patch to see if it resolves your issue. I am going to try to add a unit test by mocking a custom endpoint that provides the default args & options this code is designed to extend, see #39264.
Thanks.
#3
@
8 years ago
- Summary changed from problem in wp-api.js line 205 to `wp.api.utils.decorateFromRoute` should use `_.extend` not `_.union`
#6
@
8 years ago
Tracking in https://github.com/WP-API/client-js/pull/154
#8
follow-up:
↓ 9
@
8 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for 4.7.3 consideration.
@Magenta Cuda thanks for the bug report. I am going to look into this, can I ask you though why you are raising it as a bug, did you come across somewhere trying to use the library and it failed because of this code? eg. does using
_.union
here vs_.extend
actually break something, or are you noting it seems wrong on a pure code bases. If this does cause some demonstrable issue, I'd like to write a unit test demonstrating that so we can verify the code changes fixes the issue.