Skip to content

PATCH Successfully but Return Data is Null #870

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

Closed
falestra opened this issue Oct 31, 2020 · 6 comments · Fixed by #875
Closed

PATCH Successfully but Return Data is Null #870

falestra opened this issue Oct 31, 2020 · 6 comments · Fixed by #875
Labels

Comments

@falestra
Copy link

Description

I tried to PATCH the department resource. Request body as below:

PATCH /departments/10
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
    "data": {
        "type": "departments",
        "id": "10",
        "attributes": {
            "name": "Department 10",
            "description": ""
        }
    }
}

The data has been changed successfully, but the response data received is: null.

{
    "links": {
        "self": "http://localhost:5000/departments/10"
    },
    "data": null
}

The response should have received changed data right?
...

Environment

  • JsonApiDotNetCore Version: 4.0.0-beta1
@bart-degreed
Copy link
Contributor

This is by design. See the json:api spec. We only return the changed resource when the update caused side effects in attributes that the client cannot know about.

@bkoelman
Copy link
Member

bkoelman commented Nov 1, 2020

Relevant quote from the json:api spec:

204 No Content
If an update is successful and the server doesn’t update any fields besides those provided, the server MUST return either a 200 OK status code and response document (as described above) or a 204 No Content status code with no response document.

@bkoelman
Copy link
Member

bkoelman commented Nov 1, 2020

This is actually broken in master (which returns 200 with data:null instead of 204), but fixed in #851, which we'll merge before the next release.

@falestra
Copy link
Author

falestra commented Nov 1, 2020

Ok if it's like that. I'm just learning the json: api spec. So, does PATCH not return modified data?

Thank you for the quick response.

@bart-degreed
Copy link
Contributor

Only when side effects occur. For example, if you have a database trigger that sets LastModifiedAt column on each update. The api user cannot know, so we send back the full resource. If there are no side effects, we don't send back the resource for efficiency. The client already knows what has changed.

@falestra
Copy link
Author

falestra commented Nov 1, 2020

Thanks for the information. With this explanation, I can understand.

This was referenced Nov 6, 2020
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.

3 participants