Skip to content

Commit 0a1bb94

Browse files
author
Gauvain Pocentek
committed
Rework the Gitlab.delete method
Fixes #107
1 parent c3f5b3a commit 0a1bb94

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

gitlab/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,18 @@ def delete(self, obj, id=None, **kwargs):
471471
if inspect.isclass(obj):
472472
if not issubclass(obj, GitlabObject):
473473
raise GitlabError("Invalid class: %s" % obj)
474-
params = {}
475-
params[obj.idAttr] = id
476-
else:
477-
params = obj.__dict__.copy()
474+
475+
params = {obj.idAttr: id if id else getattr(obj, obj.idAttr)}
478476
params.update(kwargs)
477+
479478
missing = []
480479
for k in itertools.chain(obj.requiredUrlAttrs,
481480
obj.requiredDeleteAttrs):
482481
if k not in params:
483-
missing.append(k)
482+
try:
483+
params[k] = getattr(obj, k)
484+
except KeyError:
485+
missing.append(k)
484486
if missing:
485487
raise GitlabDeleteError('Missing attribute(s): %s' %
486488
", ".join(missing))
@@ -493,6 +495,10 @@ def delete(self, obj, id=None, **kwargs):
493495
# url-parameters left
494496
for attribute in obj.requiredUrlAttrs:
495497
del params[attribute]
498+
if obj._id_in_delete_url:
499+
# The ID is already built, no need to add it as extra key in query
500+
# string
501+
params.pop(obj.idAttr)
496502

497503
try:
498504
r = self.session.delete(url,

0 commit comments

Comments
 (0)