Skip to content

Bug: TypeError: can't access property "self", data._jv.links is undefined on patchRelated #15

@durk-cacholong

Description

@durk-cacholong

🐛 Bug: TypeError: can't access property "self", data._jv.links is undefined on patchRelated

Description

A TypeError is thrown when performing a PATCH request on a relationship endpoint.
The error occurs even though the server response appears to be a valid JSON:API document.

This seems to happen because the response does not include links.self, and the client code attempts to access it unconditionally.


Error

TypeError: can't access property "self", data._jv.links is undefined
    writeRelated actions.js:75
    patchRelated actions.js:276
    wrappedAction pinia.mjs:1400
    actionName pinia.mjs:955

Endpoint

PATCH /some-resource/resource-4e4e-467a-8f7c-uuid/relationships/some-related-resource

Request Body

{
  "data": [
    {
      "type": "some-related-resource",
      "id": "some-85ca-43ed-8028-uuid"
    }
  ]
}

Response Body

{
  "jsonapi": {
    "version": "1.0"
  },
  "data": [
    {
      "type": "some-related-resource",
      "id": "some-85ca-43ed-8028-uuid"
    }
  ]
}

Expected Behavior

  • The relationship update succeeds without throwing an error.
  • The client should either:
    • Handle responses without links.self, or
    • Accept a 204 No Content response for relationship PATCH requests, which is valid per JSON:API.

Actual Behavior

  • The request succeeds server-side, but the client throws:
    TypeError: can't access property "self", data._jv.links is undefined
    
  • Execution fails in writeRelated / patchRelated.

Notes

  • According to the JSON:API specification, a PATCH request to a relationship endpoint may return 204 No Content, and response bodies are optional.
  • When a response body is returned, links are optional and should not be assumed to exist.

Possible Fix

  • Add a null/undefined guard when accessing data._jv.links.self
  • Or skip link processing for relationship PATCH responses

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