Defect #33744
openREST API ignores null assigned_to_id when updating an issue
Description
Hi there,
assigning a different user using the JSON REST API works perfectly on 4.1.1.stable when we assign to a specific user ID.
However, when trying to unassign a user, the request is simply ignored. I tried putting null, 0, -1 or "" as the user ID, but nothing works; I believe this to be a defect.
Best,
Johannes
Files
Related issues
Updated by Yuichi HARADA over 6 years ago
I was able to unassign the Assignee with the following REST-API command, referring to Rest_Issues.
curl -X PUT -H "Content-Type: application/json" -H "X-Redmine-API-Key: <API KEY>" -d '{"issue": {"assigned_to_id": ""}}' http://127.0.0.1:3000/issues/1.json
If you can't update with the above command, it is possible that Edit issues permission is disabled for the user running the command.
Updated by Holger Just about 6 years ago
- Has duplicate Defect #33877: REST API: No way of removing Assigned To when Issue is assigned added
Updated by Artur Weigandt 14 days ago
I can confirm this on Redmine 5.1, 6.0, 6.1 and 7.0. The behaviour depends on the request format.
I updated an issue that had assigned_to_id set and sent an empty value, then fetched the issue again. All requests returned 204 No Content. The result is the same on all four versions:
| Request body | assigned_to_id |
|---|---|
XML <assigned_to_id></assigned_to_id> |
still assigned |
JSON {"assigned_to_id": ""} |
unassigned |
I also tested the following on Redmine 7.0.2 (an issue category was unassigned in every case):
| Request body | Issue |
|---|---|
XML <assigned_to_id/> |
still assigned |
XML <assigned_to_id nil="true"/> |
still assigned |
JSON {"assigned_to_id": null} |
still assigned |
So an empty string in a JSON request is the only way to unassign an issue through the REST API, as noted above. XML requests (with an empty or nil value) and JSON null are silently ignored, and the response is still a successful 204, so the client cannot tell that nothing happened.
Workaround:
PUT /issues/1.json
Content-Type: application/json
{"issue": {"assigned_to_id": ""}}
A client-side fix using this workaround: php-redmine-api #512.
Updated by Go MAEDA 10 days ago
- File 0001-Allow-unassigning-an-issue-via-the-REST-API-with-a-n.patch 0001-Allow-unassigning-an-issue-via-the-REST-API-with-a-n.patch added
- Status changed from New to Confirmed
- Target version set to Candidate for next minor release
I confirmed this issue on the current trunk.
When updating an issue via the REST API, "assigned_to_id": null in JSON or an empty element such as <assigned_to_id/> in XML returns 204 No Content, but the assignee is not changed.
Both values are received as nil, and Issue#safe_attributes= applies assigned_to_id only when its value is truthy. As a result, there is currently no way to unassign an issue with the XML API. With the JSON API, an empty string ("assigned_to_id": "") works as a workaround.
The attached patch fixes this by checking whether the assigned_to_id key is present instead of checking its value. Tests for both JSON and XML are included.
Updated by Go MAEDA 1 day ago
- Subject changed from REST API does not allow unassigning user to REST API ignores null assigned_to_id when updating an issue
- Status changed from Confirmed to Resolved
- Assignee set to Go MAEDA
- Resolution set to Fixed
Committed the fix in r25455. Thank you all for reporting this issue.