Updating a "patch" state via REST

Markus Mayer mmayer at broadcom.com
Wed Oct 10 09:33:23 AEDT 2018


Hi,

I am working on a script that will, amongst other things, update the
state ("Accepted", "Rejected", etc.) of patches in our own Patchwork
installation. The script is using the REST API. All requests in the
script, so far, are GET requests. They work fine.

Now, I want to issue a PUT request to update the patch state, also
using the REST API. However, no matter what I try, the request gets
rejected by the server.

I have been experimenting with a docker installation of Patchwork.
This is not the live instance:

$ curl -S -i 'http://localhost:8000/api/1.0/patches/1/'
HTTP/1.0 200 OK
Date: Tue, 09 Oct 2018 22:23:56 GMT
Server: WSGIServer/0.2 CPython/3.6.6
Content-Type: application/json
Vary: Accept, Cookie
Allow: GET, PUT, PATCH, HEAD, OPTIONS
X-Frame-Options: SAMEORIGIN

{"id":1,"url":"http://localhost:8000/api/1.0/patches/1/","project":{"id":2,"url":"http://localhost:8000/api/1.0/projects/2/","name":"Test","link_name":"Test","list_id":"Test","list_email":"...","web_url":"","scm_url":"","webscm_url":""}
[...]

Okay, so patch 1 exists and we can retrieve information about it.

First attempt to update the state:

$ curl -i -X PUT -H 'Content-Type: application/json' -d
'{"state":"Rejected"}'
'http://patchwork:passwd@localhost:8000/api/1.0/patches/1/'
HTTP/1.0 400 Bad Request
Date: Tue, 09 Oct 2018 22:22:58 GMT
Server: WSGIServer/0.2 CPython/3.6.6
Content-Type: application/json
Vary: Accept, Cookie
Allow: GET, PUT, PATCH, HEAD, OPTIONS
X-Frame-Options: SAMEORIGIN

{"delegate":["This field is required."]}

Okay, so it wants the delegate field to be present. Not sure why,
since I don't really want to set the delegate yet, but okay.

Second attempt:

$ curl -i -X PUT -H 'Content-Type: application/json' -d
'{"delegate":1, "state":"Rejected"}'
'http://patchwork:passwd@localhost:8000/api/1.0/patches/1/'
HTTP/1.0 400 Bad Request
Date: Tue, 09 Oct 2018 22:25:43 GMT
Server: WSGIServer/0.2 CPython/3.6.6
Content-Type: application/json
Vary: Accept, Cookie
Allow: GET, PUT, PATCH, HEAD, OPTIONS
X-Frame-Options: SAMEORIGIN

{"delegate":{"non_field_errors":["Invalid data. Expected a dictionary,
but got int."]}}

Okay, so delegate needs to be a dictionary.

Third attempt:

$ curl -i -X PUT -H 'Content-Type: application/json' -d '{"delegate" :
{"id" : 1},"state":"Rejected"}'
'http://patchwork:passwd@localhost:8000/api/1.0/patches/1/'
HTTP/1.0 500 Internal Server Error
Date: Tue, 09 Oct 2018 22:26:44 GMT
Server: WSGIServer/0.2 CPython/3.6.6
Content-Type: text/plain
X-Frame-Options: SAMEORIGIN
Vary: Cookie

AssertionError at /api/1.0/patches/1/
The `.update()` method does not support writable nested fields by default.
Write an explicit `.update()` method for serializer
`patchwork.api.patch.PatchDetailSerializer`, or set `read_only=True`
on nested serializer fields.

Request Method: PUT
Request URL: http://localhost:8000/api/1.0/patches/1/
Django Version: 1.10.8
Python Executable: /usr/bin/python3
Python Version: 3.6.6
Python Path: ['/home/patchwork/patchwork', '/usr/lib/python36.zip',
'/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages']
Server time: Tue, 9 Oct 2018 22:26:44 +0000

So, does that mean that Patchwork doesn't currently support this type
of functionality using the REST API? The error message seems to imply
that code changes to the Patchwork core are needed to make this work.

Can you provide me with some pointers where to go from here?

Thanks,
-Markus


More information about the Patchwork mailing list