Skip to content

Sparse fields nulling meta fields instead of removing them #332

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
approxit opened this issue Mar 9, 2017 · 0 comments · Fixed by #1221
Closed

Sparse fields nulling meta fields instead of removing them #332

approxit opened this issue Mar 9, 2017 · 0 comments · Fixed by #1221
Labels

Comments

@approxit
Copy link

approxit commented Mar 9, 2017

Hi,

JSON API specification doesn't say anything about meta fields while using sparse fields, but with drf-json-api 2.1.1 implementation we actually have control over meta files presence in response. The thing is - we can't get rid of meta fields totally. Values of meta fields are nulled, and this is a quite impact for the actual information.

Let's take example:

GET /resource1/1/
{
    "data": {
        "type": "resource1",
        "id": "1",
        "attributes": {
            "some_field": 1,
            "some_other_field": 2
        },
        "meta": {
            "some_meta_field": 3,
            "some_other_meta_field": 4
        }
    }
}
GET /resource1/1/?fields[resource1]=some_field
{
    "data": {
        "type": "resource1",
        "id": "1",
        "attributes": {
            "some_field": 1
        },
        "meta": {
            "some_meta_field": null,
            "some_other_meta_field": null
        }
    }
}
GET /resource1/1/?fields[resource1]=some_meta_field
{
    "data": {
        "type": "resource1",
        "id": "1",
        "attributes": {},
        "meta": {
            "some_meta_field": 3,
            "some_other_meta_field": null
        }
    }
}

Take note that null value is a totally natural and legal value in application logic. Here we receives wrong information. It's a bug for me. drf-json-api must decide to drop limiting meta fields by sparse fields or to remove meta fields totally by sparse fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants