Skip to content
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

Avoid primary data to occur in included[] #1195

Closed
bkoelman opened this issue Sep 30, 2022 · 1 comment · Fixed by #1197
Closed

Avoid primary data to occur in included[] #1195

bkoelman opened this issue Sep 30, 2022 · 1 comment · Fixed by #1197
Labels

Comments

@bkoelman
Copy link
Member

bkoelman commented Sep 30, 2022

DESCRIPTION

The primary resource is duplicated in the included array in rare corner cases, such as self-referencing relationships or cyclic relationship chains.

I don't know if this was a deliberate choice or just an unnoticed side effect during initial implementation (many years ago, before I joined the project). The behavior could be considered convenient, because clients parsing the included array can look up everything in the array, without falling back to the primary data.

We've changed the logic to build the include array multiple times. But before doing so, we added tests to capture the existing behavior. Therefore it's still working this way today.

The JSON:API specification used to be agnostic about this, but with its recent rewording, this is no longer allowed:

Every included resource object MUST be identified via a chain of relationships originating in a document’s primary data. This means that compound documents require “full linkage” and that no resource object can be included without a direct or indirect relationship to the document’s primary data.

The only exception to the full linkage requirement is when relationship fields that would otherwise contain linkage data are excluded due to sparse fieldsets requested by the client.

STEPS TO REPRODUCE

See cases in IntegrationTests/QueryStrings/Includes/IncludeTests.cs.

EXPECTED BEHAVIOR

The primary resource is never duplicated in the included array in response bodies.

ACTUAL BEHAVIOR

Duplication may occur.

VERSIONS USED

  • JsonApiDotNetCore version: 5.0.3
  • ASP.NET Core version: 6.0
  • Entity Framework Core version: N/A
  • Database provider: N/A
@bkoelman bkoelman added the bug label Sep 30, 2022
@bkoelman
Copy link
Member Author

/cc @maurei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

1 participant