Project

General

Profile

Actions

Defect #33744

closed

REST API ignores null assigned_to_id when updating an issue

Defect #33744: REST API ignores null assigned_to_id when updating an issue

Added by Johannes Bauer over 6 years ago. Updated 19 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
REST API
Target version:
Resolution:
Fixed
Affected version:

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 1 (0 open — 1 closed)

Has duplicate Redmine - Defect #33877: REST API: No way of removing Assigned To when Issue is assignedClosedActions

Updated by Yuichi HARADA over 6 years ago Actions #1

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 over 6 years ago Actions #2

  • Has duplicate Defect #33877: REST API: No way of removing Assigned To when Issue is assigned added

Updated by Artur Weigandt about 1 month ago Actions #3

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 about 1 month ago Actions #4

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 29 days ago Actions #5

  • Target version changed from Candidate for next minor release to 6.1.7

Setting the target version to 6.1.7.

Updated by Go MAEDA 25 days ago Actions #6

  • 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.

Updated by Go MAEDA 19 days ago Actions #7

  • Status changed from Resolved to Closed

Merged the fix into the stable branches in r25460 and r25461.

Actions

Also available in: PDF Atom