View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0025407 | mantisbt | api rest | public | 2019-01-31 08:20 | 2024-08-25 04:31 |
Reporter | eternalstorms | Assigned To | dregad | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | iMac 5k, 2017 | OS | macOS | OS Version | 10.14.2 (18C54) |
Product Version | 2.18.0 | ||||
Target Version | 2.26.3 | Fixed in Version | 2.26.3 | ||
Summary | 0025407: Resetting version fields to empty is not possible | ||||
Description | After having set a "fixed_in_version" value for an issue upon resolving it, when I'd like to re-open that issue, I'd also like to reset "fixed_in_version" to an empty value, because obviously, it wasn't fixed if I had to reopen the issue. I tried passing an empty dictionary a null object: a null-value dictionary: or leaving the dictionary's values empty: nothing worked. For other fields (like handler, or status) using an empty dictionary: | ||||
Additional Information | MantisBT 2.18.0 | ||||
Tags | No tags attached. | ||||
or am I just missing something? |
|
I can reproduce the behavior. It applies not only to fixed_in_version, but to the other version fields as well (version, target_version). Problem seems to be in mc_issue_update() function, which is ignoring null versions instead of unsetting the field. |
|
@dregad I looked at the PR in 0025407:0068843 - the lack of providing the field shouldn't reset the field's value to blank. The update behavior should use a PATCH semantics. The right way to empty a version field is to explicitly set its code |
|
It does not. Consider this test issue
If I update the issue as follows
Note that version and target_version, which are not specified in the payload, are not modified.
PATCH is indeed what is being used here, I'm not sure why you're mentioning that. Can you clarify ?
With a payload like I think my proposed fix
Based on the above, I don't think it's beneficial to be more strict. I'm OK to adapt the code, so that |
|
@dregad I may have misinterpreted the code relating to the patch semantics.
|
|
The anonymous functions I introduced are only here to reduce code duplication, they are not actually changing the semantics. The meaningful change here, is the removal of the But I can add a comment if you want.
Can you clarify your intention ? Is that
OK will do once you have answered the question above. |
|
Actually the PATCH semantics are handled in the parent function rest_issue_update(), which merges the REST payload with the issue data from the DB. But I'll add PHPDoc for the anonymous functions anyway. And also fix a small bug I found while analyzing this ;-) |
|
yes, only empty the field when id = 0 or name = ''. So that is the option I'm suggesting. Note that different languages can serialize json structures differently and generate null values when fields not set, etc. So it would be good to be consistent with the schema and provide standard way to do such behavior.
Just keep in mind that such APIs are typically used from REST and SOAP APIs. |
|
I think this makes things unnecessarily strict, but fine, I'll do as you say. This will require changes in rest_issue_update() to validate input before passing the payload on to mc_issue_update() for processing, to ensure we have no regression on SOAP API.
I would be very surprised if that were the case. Do you have evidence to support that statement ?
Pardon my ignorance, but you have referred to this schema several times and I'm not aware of its existence... Is it something that you manage in Postman ? Can you please point me to where I can find it ?
I see no problem here, as SOAP API does not have the notion of a patch request. mc_issue_update() expects a whole Issue as payload, and if you call it with missing or null fields, they will be cleared. It is the client's responsibility to call mc_issue_get() first to retrieve current values, which is precisely what rest_issue_update() does. |
|
@vboctor I finally managed to get back to this.
I analysed the API's current behavior with regards to specifying a version when adding a new issue (i.e. POST /issues). Your original implementation (see MantisBT master 8df25e99) currently accepts the following:
Based on this, I believe that the way I currently implemented the PATCH /issues endpoint is correct and consistent with the existing behavior. Restricting the possibility of clearing the version to only I have updated the PR, to document the anonymous functions (PHPDoc) and add PHPUnit tests which reflect the current behavior. I propose to merge as-is to resolve this issue. If you still feel that the REST API should be more restrictive (per your note 0025407:0068853) then you can open another issue to track that, considering that this change should be applied globally (POST & PATCH /issues), . Independently from that, I noted the following inconsistent behavior, which successfully (and incorrectly IMO) clears the version:
I propose to fix these separately (added @TODO notes in the Test script). I would still be interested in having your answer to this question:
|
|
MantisBT: master-2.26 cb0e07f3 2024-04-19 13:45 Details Diff |
REST: allow clearing version fields Until now it was not possible to set an issue's version, target_version and fixed_in_version to blank. Fixes 0025407 |
Affected Issues 0025407 |
|
mod - api/soap/mc_issue_api.php | Diff File | ||
MantisBT: master-2.26 bddcc92a 2024-04-21 18:08 Details Diff |
Allow id 0 and name '' to clear version The following Version payloads can now be used to unset Version fields: - `"version": {"id": 0}` - `"version": {"name": ""}` Prior to this, it was only possible with `"version": null`, `"version": ""` and `"version": {}`. Fixes 0025407 |
Affected Issues 0025407 |
|
mod - api/soap/mc_api.php | Diff File | ||
mod - api/soap/mc_issue_api.php | Diff File | ||
MantisBT: master-2.26 9f6f7350 2024-05-12 09:55 Details Diff |
Add PHPUnit test to update Issue Version via REST At the moment the tests are reflecting the API's current behavior, which may not be the intended result. See discussion in issue 0025407. |
Affected Issues 0025407 |
|
add - tests/rest/RestIssueUpdateVersion.php | Diff File |