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

Sparse fields - Throws InvalidValueException when list of a model fields includes id field #1917

Closed
thaingo opened this issue Mar 15, 2021 · 2 comments

Comments

@thaingo
Copy link
Contributor

thaingo commented Mar 15, 2021

Upgrade to Elide 5.0.0-pr32 from 5.0.0-pr30 and all previously working json APIs, that uses fields query on a model to list its fields including id, are not working any more.

Expected Behavior

fields query should work after an upgrade to 5.0.0-pr32.

Current Behavior

When fields query is used on a model to list of wanted fields which also includes id field, then following error occurs when its associated json API endpoint gets called by a http client:
com.yahoo.elide.core.exceptions.InvalidValueException: Invalid value: **entityXXX** does not contain the fields: [id]

Possible Solution

Remove field id from list of included model fields.

Steps to Reproduce (for bugs)

  1. Use Elide spring boot example with latest version: 5.0.0-pr32
  2. Issue a http GET request using fields query parameter to specify a model and include its field id
  3. InvalidValueException will be thrown

Your Environment

  • Elide version used: 5.0.0-pr32
  • Environment name and version (Java 1.8.0_152): JDK 15 (java version "15" 2020-09-15)
  • Operating System and version: MacOS
  • Link to your project: N/A
@aklish
Copy link
Member

aklish commented Mar 15, 2021

This was introduced by the following PR to be more strict with JSON-API sparse fields (to catch client errors):

#1801

To my knowledge, ID is not considered a field in JSON-API:
https://jsonapi.org/format/#document-resource-object-fields

Fields consist of attributes and relationships. ID is something different and it is always included in the response (there is no way to exclude it).

Given that understanding, my intuition is that the latest Elide release has the correct behavior and the bug was allowing ID in sparse fields in earlier versions.

We only introduced this change in Elide 5 to avoid breaking Elide 4 users.

@thaingo
Copy link
Contributor Author

thaingo commented Mar 16, 2021

Noted with thanks.

@thaingo thaingo closed this as completed Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants