Post to `bug/{bugid}/comment` returns wrong `comment_id`
Categories
(bugzilla.mozilla.org :: API, defect)
Tracking
()
People
(Reporter: mvanstraten, Unassigned, NeedInfo)
References
Details
In the docs, it states that a call to https://bmo.readthedocs.io/en/latest/api/core/v1/comment.html#create-comments returns the id
of the created comment.
I have used the API for multiple month now, collecting output data. And on the production side, so https://bugzilla.mozilla.org
the returned comment_id
is always wrong.
For example this comment on the bug https://bugzilla.mozilla.org/rest/bug/1702411?include_fields=comments, with the comment_id
16772470 was created via the API call, but the returned comment_id
from the create call was 1222250.
Weird is that this doesn't happen on https://bugzilla-dev.allizom.org/.
Reporter | ||
Comment 1•1 year ago
|
||
For reference, the scripts in question are found here: https://phabricator.services.mozilla.com/D193589.
Comment 2•1 year ago
|
||
This is a test comment using REST API
Reporter | ||
Comment 3•1 year ago
•
|
||
This for some reason works without a problem:
import json
import bugzilla
BMO_URL = "https://bugzilla.mozilla.org/rest"
TEST_BUG = 1877206
API_KEY = "<YOUR KEY>"
bugzilla_client = bugzilla.Bugzilla(url=BMO_URL, api_key=API_KEY)
# def post_comment(bugid, api_key, payload):
# headers = {"Content-Type": "application/json"}
# res = post(f"{BMO_URL}/bug/{bugid}/comment?api_key={api_key}",
# headers=headers, data=json.dumps(payload))
# return res.json()
payload = {"id": TEST_BUG, "comment": "debug", "is_markdown": True}
res = bugzilla_client._post(f"bug/{TEST_BUG}/comment", json.dumps(payload))
# res = post_comment(TEST_BUG, API_KEY, payload)
print(json.dumps(res))
Comment 4•1 year ago
|
||
I am unable to make this fail either using both a browser based rest client and Perl code used by BMO. We even have a test case for this which runs for all pull requests in CI. Could it be that somehow res
is being cached somehow and has an old value intermittently? It could possibly something to do with MySQL since the comment ID is a primary key, and after we create the comment in the database, we retrieved the last inserted primary key. But is not very likely another ID is being used in between that time. Will keep digging. Also The bugzilla.py module is passing API keys in the query string which we would prefer it to be in the http header. But that also should not be affecting this issue.
Given we can't reproduce it, and it works with the code in comment 2, this appears to be a client-side issue.
Reporter | ||
Comment 6•1 year ago
|
||
I will try to make a run with the scripts against the dummy bug 1877206.
Reporter | ||
Comment 7•1 year ago
•
|
||
I got this to work with the plain requests
module in python, but it only seems to work on this Bug 1711703.
The following posts to one of the bugs the scripts I noticed this in also post to, so please don't flut it.
import json
BMO_URL = "https://bugzilla.mozilla.org/rest"
API_KEY = "<YOUR API KEY>"
TEST_BUG = 1711703
def post_comment(bugid, api_key, payload):
from requests import post
headers = {"Content-Type": "application/json"}
res = post(f"{BMO_URL}/bug/{bugid}/comment?api_key={api_key}",
headers=headers, data=json.dumps(payload))
return res.json()
data = {'id': TEST_BUG, 'comment': 'Test comment investigating Bug 1877201', 'is_markdown': True}
res = post_comment(TEST_BUG, API_KEY, data)
print(json.dumps(res))
Description
•