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

Comments

pixelwhip created an issue. See original summary.

gabesullice’s picture

Title: Include intermediate resources when include is a multi-part relationship path » Spec compliance: Include intermediate resources when include is a multi-part relationship path
Category: Feature request » Bug report
Issue tags: +DX (Developer Experience)

I 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 Request along 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 :)

wim leers’s picture

Wow, superb bug report, @pixelwhip! Thank you so much!

wim leers’s picture

Title: Spec compliance: Include intermediate resources when include is a multi-part relationship path » [PP-1] Spec compliance: Include intermediate resources when include is a multi-part relationship path
Status: Active » Postponed
wim leers’s picture

Title: [PP-1] Spec compliance: Include intermediate resources when include is a multi-part relationship path » Spec compliance: Include intermediate resources when include is a multi-part relationship path
Status: Postponed » Active
gabesullice’s picture

Status: Active » Needs review
StatusFileSize
new967 bytes
new7.82 KB

Also, I think #2976108 solves at least part of this problem, if not all of it.

I think it does. Test coverage patch for when that lands, combined patch to double check.

gabesullice’s picture

Giving credit to @pixelwhip.

wim leers’s picture

I just pushed it :P It's quite likely that your combined patch will not apply because of that…

Status: Needs review » Needs work

The last submitted patch, 6: 2946537-combined.patch, failed testing. View results

gabesullice’s picture

Status: Needs work » Needs review

Still NR, as @Wim Leers's prediction was correct.

The last submitted patch, 6: 2946537-test-coverage.patch, failed testing. View results

gabesullice’s picture

Assigned: Unassigned » gabesullice
Failed asserting that Array &0 (
    0 => 'data'
    1 => 'jsonapi'
    2 => 'links'
) is identical to Array &0 (
    0 => 'data'
    1 => 'jsonapi'
    2 => 'links'
    3 => 'meta'
).

This is almost certainly an access related failure in the expectation, I'll debug/fix.

wim leers’s picture

#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..

wim leers’s picture

gabesullice’s picture

Title: Spec compliance: Include intermediate resources when include is a multi-part relationship path » [PP-1] Spec compliance: Include intermediate resources when include is a multi-part relationship path
Status: Needs review » Postponed

I suspect that this will become trivial after #2956084

Indeed, 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.

gabesullice’s picture

Title: [PP-1] Spec compliance: Include intermediate resources when include is a multi-part relationship path » [PP-1] Test coverage: Inclusion of intermediate resources when include is a multi-part relationship path
Category: Bug report » Task
Priority: Normal » Major
wim leers’s picture

AFAICT this does not work?

/jsonapi/node/article?include=uid.roles or /jsonapi/node/article?include=field_tags.vid or /jsonapi/node/article?include=field_tags.parent should include roles, vocabularies or terms, respectively, but noen of them work?

wim leers’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
wim leers’s picture

Issue tags: +API-First Initiative

This 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.

gabesullice’s picture

Priority: Major » Normal
wim leers’s picture

#2997600: Resolve included resources prior to normalization landed just now. In #2997600-24: Resolve included resources prior to normalization, @gabesullice said:

Manual testing should show that this patch does not require the intermediate field.

I tried to apply the test coverage from #2946537 and found out that it's incomplete. The actual results are correct, but the expectations are wrong.

I'm pretty sure that means this is still something that requires code changes and not just test coverage.

wim leers’s picture

Title: [PP-1] Test coverage: Inclusion of intermediate resources when include is a multi-part relationship path » Test coverage: Inclusion of intermediate resources when include is a multi-part relationship path
Status: Postponed » Needs work
wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.06 KB

Status: Needs review » Needs work

The last submitted patch, 23: 2946537-23.patch, failed testing. View results

gabesullice’s picture

The #23 failures are all because the test coverage is asserting the previous, incorrect behavior. The actual behavior is correct though.

wim leers’s picture

Assigned: gabesullice » Unassigned
Status: Needs work » Needs review
StatusFileSize
new968 bytes
new2.08 KB

Confirming #25.

This interdiff makes at least N pass. For such a trivial change, it took far longer to find/solve than I'd like to admit 😅

wim leers’s picture

StatusFileSize
new1.64 KB
new2.7 KB

Green! 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.

gabesullice’s picture

Status: Needs review » Reviewed & tested by the community

Nice work!

wim leers’s picture

Feel free to commit it — it doesn't need to be me who does that :)

  • gabesullice committed 137f087 on 8.x-2.x authored by Wim Leers
    Issue #2946537 by Wim Leers, gabesullice, pixelwhip: Test coverage:...
gabesullice’s picture

Status: Reviewed & tested by the community » Fixed

Done.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.