Skip to content

Incorrect handling of null or empty nested includes #1371

@JamesGlover

Description

@JamesGlover

This issue is a (choose one):

  • Problem/bug report.
  • Feature request.
  • Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.

Checklist before submitting:

  • I've searched for an existing issue.
  • I've asked my question on Gitter and have not received a satisfactory answer.
  • I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
  • The feature I'm asking for is compliant with the JSON:API spec.

Description

Bug reports:

When requesting nested includes eg user?include=things.box then JSON-API fails to generate a data attribute on the related resource object if the related resources are either null or empty. In the above for example, the data attribute on the relationship between thing and box would be missing if the thing did not have a box. This is in contradiction to the specification, which suggests that data should have a value of either null or [] in this case.

https://jsonapi.org/format/#document-resource-object-linkage

It appears that this bug is the result of a typo in JSON::API::ResourceTree#load_included where the lookup of includes for related resources is incorrectly using the include_related instance variable, rather than the symbol, and thus always returns nil.

I have a PR with a fix to follow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions