According to the include spec, intermediate resources should be included to provide full linkage between the base and leaf resources.
Note: Because compound documents require full linkage (except when relationship linkage is excluded by sparse fieldsets), intermediate resources in a multi-part path must be returned along with the leaf nodes. For example, a response to a request for comments.author should include comments as well as the author of each of those comments.
Currently, the included property is excluded if a relationship path is set without explicating including intermediate resources.
Example: 1
Ex. ?include=field_image_primary,field_image_primary.field_media_image
Example: 2
Ex. ?include=field_image_primary.field_media_image
Actual Result
#1 returns both entities referenced by field_image_primary and field_media_image
#2 excludes the included property from the response altogether.
Expected Result
I would expect both #1 and #2 to include both entities referenced by field_image_primary and field_media_image
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | 2946537-27.patch | 2.7 KB | wim leers |
| #27 | interdiff.txt | 1.64 KB | wim leers |
| #26 | 2946537-26.patch | 2.08 KB | wim leers |
| #26 | interdiff.txt | 968 bytes | wim leers |
| #23 | 2946537-23.patch | 1.06 KB | wim leers |
Comments
Comment #2
gabesulliceI think this is first a bug, then a feature request.
Since we don't currently support Example 2, we should be throwing a
400 Bad Requestalong with a helpful error. That error should at least suggest the request in example #1.However, it seems reasonable that both #1 and #2 should work as @pixelwhip said he expected. Adding that would solve two issues with one patch :)
Comment #3
wim leersWow, superb bug report, @pixelwhip! Thank you so much!
Comment #4
wim leersOnce #2953321: Comprehensive JSON API integration test coverage phase 5: nested includes and sparse field sets lands, test coverage will be simpler to add. Postponing.
Comment #5
wim leers#2953321: Comprehensive JSON API integration test coverage phase 5: nested includes and sparse field sets landed, adding explicit test coverage for this became a lot simpler.
Also, I think #2976108-5: Spec Compliance: Impossible to include related resources when relationship field is not in a request's sparse fieldset solves at least part of this problem, if not all of it.
Comment #6
gabesulliceI think it does. Test coverage patch for when that lands, combined patch to double check.
Comment #7
gabesulliceGiving credit to @pixelwhip.
Comment #8
wim leersI just pushed it :P It's quite likely that your
combinedpatch will not apply because of that…Comment #10
gabesulliceStill NR, as @Wim Leers's prediction was correct.
Comment #12
gabesulliceThis is almost certainly an access related failure in the expectation, I'll debug/fix.
Comment #13
wim leers#12: I think I fixed the same failure in #2956084: Impossible to raise an error when an `include` is requested for an inaccessible relationship field., or at least a related one that had the same failure output :) I suspect that this will become trivial after #2956084: Impossible to raise an error when an `include` is requested for an inaccessible relationship field..
Comment #14
wim leersComment #15
gabesulliceIndeed, I stopped tinkering with this because #2956084: Impossible to raise an error when an `include` is requested for an inaccessible relationship field. was just too much of a pain to work around. Let's postpone this one one that.
Comment #16
gabesulliceThis works as of #2976108: Spec Compliance: Impossible to include related resources when relationship field is not in a request's sparse fieldset, it just needs tests to prove it.
Comment #17
wim leersAFAICT this does not work?
/jsonapi/node/article?include=uid.rolesor/jsonapi/node/article?include=field_tags.vidor/jsonapi/node/article?include=field_tags.parentshould include roles, vocabularies or terms, respectively, but noen of them work?Comment #18
wim leersComment #19
wim leersThis is blocked on #2956084: Impossible to raise an error when an `include` is requested for an inaccessible relationship field.. But that is a normal task. Either this issue needs to be downgraded to a normal task too, or we need to upgrade #2956084 to major.
Comment #20
gabesulliceComment #21
wim leers#2997600: Resolve included resources prior to normalization landed just now. In #2997600-24: Resolve included resources prior to normalization, @gabesullice said:
I'm pretty sure that means this is still something that requires code changes and not just test coverage.
Comment #22
wim leers#2956084: Impossible to raise an error when an `include` is requested for an inaccessible relationship field. landed! This is unblocked now :)
Comment #23
wim leersComment #25
gabesulliceThe #23 failures are all because the test coverage is asserting the previous, incorrect behavior. The actual behavior is correct though.
Comment #26
wim leersConfirming #25.
This interdiff makes at least
Npass. For such a trivial change, it took far longer to find/solve than I'd like to admit 😅Comment #27
wim leersGreen! Yay :)
While debugging to spot the root cause (fixed in #26), I did spot one other bug, but it's one that didn't actually manifest itself in any way. Yet. The bug:
getExpectedIncludedResourceResponse()always uses the tested resource type to look up internal field names. But it should actually be using the resource type of the current entity when evaluating a nested include path/expression.Comment #28
gabesulliceNice work!
Comment #29
wim leersFeel free to commit it — it doesn't need to be me who does that :)
Comment #31
gabesulliceDone.