Skip to content

Parser not supporting removal in many-to-many relationships #14

@TomaszChrosniak

Description

@TomaszChrosniak

Hi,

The atomic_operations.prasers.AtomicOperationParser parser does not support removal of many-to-many relationships, as described in the Atomic Operations documentation:

POST /operations HTTP/1.1
Host: example.org
Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/atomic"
Accept: application/vnd.api+json;ext="https://jsonapi.org/ext/atomic"

{
  "atomic:operations": [{
    "op": "remove",
    "ref": {
      "type": "articles",
      "id": "1",
      "relationship": "comments"
    },
    "data": [
      { "type": "comments", "id": "12" },
      { "type": "comments", "id": "13" }
    ]
  }]
}

If the op code is remove and you provide both ref and data keys in the operation document, and the latter is associated with a list, the parser then treats that value as a dict and attempts to read the type key from it, resulting in an exception.

The issue is related to this code:

resource_identifier_object=operation.get(
"data", operation.get("ref")
),

...where ref is only read as a fallback, if data is not found.

This causes this line to fail:

parsed_data["type"] = resource_identifier_object.get("type")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions