Bug 1414063 - Cannot update bug with a comment
Summary: Cannot update bug with a comment
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Bugzilla
Classification: Community
Component: WebService
Version: 5.0
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: PnT DevOps Devs
QA Contact: tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-01-17 16:08 UTC by Martin Kosek
Modified: 2025-10-16 23:48 UTC (History)
7 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2017-02-15 23:50:16 UTC
Embargoed:


Attachments (Terms of Use)
Reproducer (751 bytes, text/plain)
2017-02-15 15:34 UTC, Martin Kosek
no flags Details

Description Martin Kosek 2017-01-17 16:08:48 UTC
Description of problem:

I cannot update Bugzilla with a comment entered:

$ python
...
>>> r = s.put('https://beta.bugzilla.redhat.com/bugzilla/rest/bug/1285012', data={'cf_devel_whiteboard': u'test2', 'comment':{u'body': u'test comment2', 'is_private': False}, 'Bugzilla_token':u'xxxxxxxxx'})
>>> print r.json()
{u'code': 100500, u'message': u'Not a HASH reference at /var/www/html/bugzilla/Bugzilla/WebService/Bug.pm line 746.\n', u'documentation': u'https://beta.bugzilla.redhat.com/bugzilla/docs/en/html/api/index.html', u'error': True}

When I do not have comment hash there, update works:
>>> r = s.put('https://beta.bugzilla.redhat.com/bugzilla/rest/bug/1285012', data={'cf_devel_whiteboard': u'test2', 'Bugzilla_token':u'xxxxxxxxx'})
>>> print r.json()
{u'bugs': [{u'alias': [], u'changes': {u'cf_devel_whiteboard': {u'removed': u'', u'added': u'test2'}}, u'id': 1285012, u'last_change_time': u'2017-01-17T16:00:39Z'}]}

This is the documentation I used:
https://beta.bugzilla.redhat.com/bugzilla/docs/en/html/api/core/v1/bug.html#update-bug

Version-Release number of selected component (if applicable):
5.0.3.rh18

How reproducible:
Always

Steps to Reproduce:
1. Run example Python above
2.
3.

Actual results:
Command always fails

Expected results:
Update with a comment succeeds!

Additional info:

Comment 1 Martin Kosek 2017-01-17 22:18:28 UTC
BTW, I think there is some systematic error either on my or Bugzilla side, I receive similar error with Flag update:

>>> r = s.put('https://beta.bugzilla.redhat.com/bugzilla/rest/bug/1346342', data={'flags': [{'status': '+', 'name': 'devel_ack'}], 'Bugzilla_token': u'xxxxxxxxxx'})
>>> print r.json()
{u'code': 100500, u'message': u'Can\'t use string ("status") as a HASH ref while "strict refs" in use at /var/www/html/bugzilla/Bugzilla/WebService/Util.pm line 49.\n', u'documentation': u'https://beta.bugzilla.redhat.com/bugzilla/docs/en/html/api/index.html', u'error': True}

Comment 3 Jeff Fearn 🐞 2017-02-08 01:35:38 UTC
I can't duplicate this using perl, if the issue is still occurring please provide a complete example for testing. 

https://beta-bugzilla.redhat.com/show_bug.cgi?id=1285012#c12
https://beta-bugzilla.redhat.com/show_bug.cgi?id=1285012#c13
https://beta-bugzilla.redhat.com/show_bug.cgi?id=1285012#c14

Comment 5 Martin Kosek 2017-02-15 15:34:34 UTC
Created attachment 1250634 [details]
Reproducer

Let me attach full Python example that can be used for testing.

Comment 6 Jeff Fearn 🐞 2017-02-15 23:50:16 UTC
You need to s/data/json/ in your script.

Also, API_KEYs really do make scripting easier :)

$ cat rest-test.py
#!/usr/bin/python2

import sys

APIKEY='SECRET'

import requests
s = requests.Session()

r = s.put('https://beta-bugzilla.redhat.com/rest/bug/1346342', json={'comment':{u'body': u'test comment', 'is_private': False}, 'Bugzilla_api_key': APIKEY})

print "Result code:", r.status_code
print "Result text", r.text


$ ./rest-test.py
Result code: 200
Result text {"bugs":[{"changes":{},"id":1346342,"last_change_time":"2017-02-15T23:44:03Z","alias":[]}]}

Comment 7 Martin Kosek 2017-02-16 07:24:01 UTC
Thanks Jeff! Your advise worked! Now back to porting our tool to the new (nice) Bugzilla REST API.

Comment 8 Steve Kuznetsov 2019-06-26 16:12:15 UTC
What was the actual issue here and what, specifically, is the fix? Minimal reproducer:

$ curl -X PUT --data '{"status":"POST"}' "https://bugzilla.redhat.com/rest/bug/1705657?api_key=$KEY"
{"documentation":"https://bugzilla.redhat.com/docs/en/html/api/index.html","error":true,"code":100500,"message":"Can't use string (\"{\"ids\":[1705657],\"status\":\"POST\"\") as a HASH ref while \"strict refs\" in use at /var/www/html/bugzilla/Bugzilla/Bug.pm line 3120.\n"}

Comment 9 Steve Kuznetsov 2019-06-26 16:13:23 UTC
Err, had the wrong output, but the output just mirrors whatever I PUT:

{"documentation":"https://bugzilla.redhat.com/docs/en/html/api/index.html","error":true,"code":100500,"message":"Can't use string (\"{\"status\":\"POST\"}\") as a HASH ref while \"strict refs\" in use at /var/www/html/bugzilla/Bugzilla/Bug.pm line 3120.\n"}

Comment 10 Steve Kuznetsov 2019-06-26 16:16:07 UTC
Ah, looks like the server expects the header: "Content-Type: application/json"

This should be updated in the documentation:
https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#update-bug

Comment 11 jyotikumar 2021-10-21 09:23:05 UTC Comment hidden (spam)

Note You need to log in before you can comment on or make changes to this bug.