Skip to content

Sparse fields nulling meta fields instead of removing them #332

Closed
@approxit

Description

@approxit

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions