Skip to content

Commit ba991a8

Browse files
committed
Simplify createbug() API to accept a dict like query()
But in a back compatible way.
1 parent f367334 commit ba991a8

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

bin/bugzilla

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def _do_new(bz, opt):
706706

707707
if opt.test_return_result:
708708
return data
709-
b = bz.createbug(**data)
709+
b = bz.createbug(data)
710710
b.refresh()
711711
return [b]
712712

bugzilla/base.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,20 +1198,29 @@ def updateattachmentflags(self, bugid, attachid, flagname, **kwargs):
11981198
createbug_required = ('product', 'component', 'summary', 'version',
11991199
'description')
12001200

1201-
def _createbug(self, **data):
1202-
'''Raw xmlrpc call for createBug() Doesn't bother guessing defaults
1203-
or checking argument validity. Use with care.
1204-
Returns bug_id'''
1205-
r = self._proxy.Bug.create(data)
1206-
return r['id']
1207-
1208-
def createbug(self, **data):
1201+
1202+
def createbug(self, *args, **kwargs):
12091203
'''
12101204
Create a bug with the given info. Returns a new Bug object.
12111205
Check bugzilla API documentation for valid values, at least
12121206
product, component, summary, version, and description need to
12131207
be passed.
12141208
'''
1209+
# Previous API required users specifying keyword args that mapped
1210+
# to the XMLRPC arg names. Maintain that bad compat, but also allow
1211+
# receiving a single dictionary like query() does
1212+
if kwargs and args:
1213+
raise BugzillaError("createbug: cannot specify positional "
1214+
"args=%s with kwargs=%s, must be one or the "
1215+
"other." % (args, kwargs))
1216+
if args:
1217+
if len(args) > 1 or type(args[0]) is not dict:
1218+
raise BugzillaError("createbug: positional arguments only "
1219+
"accept a single dictionary.")
1220+
data = args[0]
1221+
else:
1222+
data = kwargs
1223+
12151224
log.debug("bz.createbug(%s)", data)
12161225

12171226
# If we're getting a call that uses an old fieldname, convert it to the
@@ -1226,8 +1235,8 @@ def createbug(self, **data):
12261235
if "check_args" in data:
12271236
del(data["check_args"])
12281237

1229-
bug_id = self._createbug(**data)
1230-
return _Bug(self, bug_id=bug_id)
1238+
rawbug = self._proxy.Bug.create(data)
1239+
return _Bug(self, bug_id=rawbug["id"])
12311240

12321241

12331242
##############################

0 commit comments

Comments
 (0)