drf-writable-nested icon indicating copy to clipboard operation
drf-writable-nested copied to clipboard

PATCH-ing object's id

Open tsunday opened this issue 7 years ago • 1 comments

I've just stumbled upon a weird case, that I was able to update object's relations with sending PATCH request containing only the updated id (pointing to another object). As it's quite handy, I would use it in my code, but is it the supported way? My friend, just found that the error for missing object is in a wrong form - it's just HTML response withmatching query does not exist instead of regular JSON response.

Here are my example request/response pairs:*

1. PATCH /users/1/

Body:

{
  "address": {
      "id": 1 // Address is a FK relation and the one with ID=1 exists
  }
}

Response:

{
  "address": {
    "street": "first",
    "city": "first city
  }
}

Comment: in this case user.address__id is updated - not the id of Address object

2. PATCH /users/1/

Body:

{
  "address": {
      "id": 999 // Address with ID=999 doesn't exist
  }
}

Response:

DoesNotExist at /users/1/
Address matching query does not exist.

tsunday avatar Jul 04 '18 10:07 tsunday

Hello @tsunday! Could you please provide an example with real code?

ruscoder avatar Jul 04 '18 11:07 ruscoder