View Issue Details

IDProjectCategoryView StatusLast Update
0032858mantisbtapi restpublic2023-10-31 16:32
Reporterdregad Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Target Version2.26.0Fixed in Version2.26.0 
Summary0032858: Status codes returned by REST API delete operations are not consistent
Description

This originates from a discussion in PR https://github.com/mantisbt/mantisbt/pull/1905.

Currently, some API endpoints return 200/204, others 400/404 and even a 403. See table below for details.

  • Returning 404 more strictly reflects the state and what happened
  • Returning success reflects that the desired outcome was achieved. This is more friendly to retries when a response fails to complete to the client. More idempotent.

We should have a consistent behavior across DELETE endpoints. It was agreed to switch to 404. The following will need to be adapted

  • Issue Tag delete /issues/{issue}/tags/{tag}
  • Project delete /projects/{project}
  • User delete /users/{user}
Additional Information
Operation Endpoint Status code
Issue delete DELETE /issues/999999 404
Issue Tag delete DELETE /issues/1/tags/999999 200
Issue note DELETE /issues/1/notes/999999 404 (400 if existing note of other issue)
Issue relationship DELETE /issues/1/relationships/99999 200 - This is a bug, fixed in 0032835
Project delete DELETE /projects/99999 403 (Access denied for deleting project.) <br> NOTE: does not use ProjectDeleteCommand !
Project user delete DELETE /projects/21/users/99999 404 (User 99999 not found)
Project version delete DELETE /projects/21/versions/99999 204 - Fixed in 0030415 / PR https://github.com/mantisbt/mantisbt/pull/1905
User delete DELETE /users/99999 204
User token delete DELETE /users/1/token/99999 404 (Token doesn't exist)
User token delete own DELETE /users/me/token/99999 404 (Token doesn't exist)
TagsNo tags attached.

Relationships

related to 0032835 closeddregad REST API errors when attempting to add or delete issue relationships 
related to 0030415 closedvboctor REST API: Add API to Get / Delete / Update versions 
related to 0032862 closedvboctor REST API documentation for Issue Tag Detach is incorrect 
related to 0032232 closeddregad Create ProjectDeleteCommand 

Activities

dregad

dregad

2023-08-25 02:50

developer   ~0068023

Project version delete will be fixed with PR https://github.com/mantisbt/mantisbt/pull/1905

dregad

dregad

2023-08-26 11:36

developer   ~0068027

On second thoughts, I believe it is better if /issues/{issue}/tags/{tag} continues to return 200 as it does today.

While it's technically a DELETE operation, we are not actually deleting the tag, just detaching it from the issue. This way we're consistent with the opposite Attach operation's behavior, which just succeeds even if the tag was already attached to the issue.

dregad

dregad

2023-08-26 13:47

developer   ~0068029

PR https://github.com/mantisbt/mantisbt/pull/1907

Related Changesets

MantisBT: master 59f62a71

2023-08-26 12:09

dregad


Details Diff
Adapt RestUserTests::testDeleteUserById()

Update the test case to prepare for change of returned status code to
404 when trying to delete a non-existing user.

Remove the assertion from RestBase::tearDown(), the check for a
successful deletion should be done in the actual test cases.

Issue 0032858
Affected Issues
0032858
mod - tests/rest/RestBase.php Diff File
mod - tests/rest/RestUserTest.php Diff File

MantisBT: master 14552850

2023-08-26 12:14

dregad


Details Diff
Add test cases for Issue Tag Attach/Detach

Covering
- attach a new tag
- attach existing tag
- detach tag
- detach unattached tag
- detach non-existing tag
- attach/detach on non-existing issue

Issue 0032858
Affected Issues
0032858
mod - tests/rest/RestIssueTest.php Diff File

MantisBT: master 40df3eb9

2023-08-26 12:19

dregad


Details Diff
TagDetachCommand: ensure tag exists

Fixes 0032858
Affected Issues
0032858
mod - core/commands/TagDetachCommand.php Diff File

MantisBT: master f095e36b

2023-08-26 12:22

dregad


Details Diff
UserDeleteCommand: ensure user exists

Fixes 0032858
Affected Issues
0032858
mod - core/commands/UserDeleteCommand.php Diff File

MantisBT: master bddf5d32

2023-08-26 13:05

dregad


Details Diff
Use ProjectDeleteCommand in rest_project_delete()

Fixes 0032232, 0032858
Affected Issues
0032232, 0032858
mod - api/rest/restcore/projects_rest.php Diff File