I am currently querying Bugzilla as follows:
r = requests.get(
"https://bugzilla.mozilla.org/rest/bug",
params={
"chfield": "[Bug creation]",
"chfieldfrom": "2015-01-01",
"chfieldto": "2016-01-01",
"resolution": "FIXED",
"limit": 200,
"api_key": api_key,
"include_fields": [
"id",
"description",
"creation_time",
],
},
)
and all I would like to add to my query is a method for ordering the bug reports. I have scoured the web for a method for ordering these results: ultimately, I would like them to be ordered from "2016-01-01"
descending. I have tried adding the following key-value pairs to params:
"order": "creation_time desc"
"sort_by": "creation_time", "order" : "desc"
"chfieldorder": "desc"
and I've tried editing the URL to be https://bugzilla.mozilla.org/rest/bug?orderBy=creation_time:desc
but none of these approaches have worked. Unfortunately, adding invalid keys fails without error: results are returned, just not in sorted order.
Ordering and ranges (ie., chfieldfrom
and chfieldto
) were not in any of the documentation that I found either.
I am aware that a hacked method of gathering ordered results would be to specify a narrow range of dates to get bug reports from, but I'm hoping there exists an actual key-value pair that can be specified to achieve the task.
Notably, of course: sorting after the request returns in r
is invalid, because the results in r
do not contain the most recent bugs.
You need to add
"order": [
"opendate DESC",
],
to your params
.
Quick test
To see more easily that it works, just run something like this after you received the response in r
:
data = json.loads(r.content)
bugs = data['bugs']
times = [x['creation_time'] for x in bugs]
print(times)
gives:
['2016-01-01T21:53:20Z', '2016-01-01T21:37:58Z', '2016-01-01T20:12:07Z', '2016-01-01T19:29:30Z', '2016-01-01T19:10:46Z', '2016-01-01T15:56:35Z',...
Details
If you are interested in the details: It looks like some fields in the Bugzilla codebase have different field names.
Take a look here https://github.com/bugzilla/bugzilla/blob/5.2/Bugzilla/Search.pm#L557:
# Backward-compatibility for old field names. Goes new_name => old_name.
# These are here and not in _translate_old_column because the rest of the
# code actually still uses the old names, while the fielddefs table uses
# the new names (which is not the case for the fields handled by
# _translate_old_column).
my %old_names = (
creation_ts => 'opendate',
delta_ts => 'changeddate',
work_time => 'actual_tFile.join(File.dirname(__FILE__), *%w[rel path here])ime',
);